From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.devel Subject: name-capture problem in completing-read Date: Fri, 1 Jun 2007 11:00:57 -0700 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1180720899 16612 80.91.229.12 (1 Jun 2007 18:01:39 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 1 Jun 2007 18:01:39 +0000 (UTC) To: "Emacs-Devel" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jun 01 20:01:38 2007 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.50) id 1HuBRM-0004da-Gd for ged-emacs-devel@m.gmane.org; Fri, 01 Jun 2007 20:01:32 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HuBRJ-0006Qo-IJ for ged-emacs-devel@m.gmane.org; Fri, 01 Jun 2007 14:01:29 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HuBRF-0006PX-2G for emacs-devel@gnu.org; Fri, 01 Jun 2007 14:01:25 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HuBRD-0006Oh-9q for emacs-devel@gnu.org; Fri, 01 Jun 2007 14:01:23 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HuBRC-0006OV-SZ for emacs-devel@gnu.org; Fri, 01 Jun 2007 14:01:22 -0400 Original-Received: from rgminet01.oracle.com ([148.87.113.118]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1HuBRC-00088z-Ag for emacs-devel@gnu.org; Fri, 01 Jun 2007 14:01:22 -0400 Original-Received: from rgmgw2.us.oracle.com (rgmgw2.us.oracle.com [138.1.186.111]) by rgminet01.oracle.com (Switch-3.2.4/Switch-3.1.6) with ESMTP id l51I1JSM011464 for ; Fri, 1 Jun 2007 12:01:19 -0600 Original-Received: from acsmt350.oracle.com (acsmt350.oracle.com [141.146.40.150]) by rgmgw2.us.oracle.com (Switch-3.2.4/Switch-3.1.7) with ESMTP id l51Bh3Wu006360 for ; Fri, 1 Jun 2007 12:01:19 -0600 Original-Received: from dhcp-amer-whq-csvpn-gw3-141-144-81-218.vpn.oracle.com by acsmt351.oracle.com with ESMTP id 2750150851180720861; Fri, 01 Jun 2007 11:01:01 -0700 X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook IMO, Build 9.0.6604 (9.0.2911.0) Importance: Normal X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3028 X-Whitelist: TRUE X-Whitelist: TRUE X-Brightmail-Tracker: AAAAAQAAAAI= X-detected-kernel: Linux 2.4-2.6 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:72029 Archived-At: I wonder if someone could help with this name-capture problem. I have a function that calls `completing-read', passing the same arguments. Some other code, invoked from the minibuffer during completion, uses the value of `minibuffer-history-variable', which is taken from the HIST parameter to `completing-read'. Whatever I name the history parameter in my function, there is a possible name clash if the value of the parameter refers to the same parameter name. For example, if the parameter is called `hist' and its value happens to be (hist . 1), then `minibuffer-history-variable' is `hist', and the value of that is (hist . 1), not whatever the value of `hist' is outside the function. Because (hist . 1) is the current value of `hist' within my function, when `minibuffer-history-variable' is `hist' that same value is picked up. I could use a macro with an uninterned symbol, but I really want to use a function. The reason is beside the point here, but this is it, FYI: In fact, I defalias `completing-read' to my function (calling the original `completing-read' definition in the function body). I need a function because I'm replacing `completing-read': other code that calls `completing-read' should pick up my redefinition instead (while in a particular minor mode; I restore the original definition of `completing-read' on mode exit). To see the problem: emacs -Q (defun my-completing-read ;; Just call original. (prompt table &optional predicate require-match initial-input hist def inherit-input-method) "" (completing-read prompt table predicate require-match initial-input hist def inherit-input-method)) (defun test () "" (interactive) (message "hist-var: `%S', val: %S" minibuffer-history-variable (symbol-value minibuffer-history-variable)) (sit-for 3)) (define-key minibuffer-local-completion-map "\C-s" 'test) (setq hist `("c" "d")) ; Or leave it unbound - makes no difference. Eval this, then, at the minibuffer prompt, hit C-s: (my-completing-read "fff: " '(("a")("b")) nil t nil (cons 'hist 1)) You'll see this: "hist-var: `hist', val: (hist . 1)" The desired behavior would have been this: "hist-var: `hist', val: ("c" "d")" `hist' is bound as a parameter to `my-completing-read', and `hist' is (correctly) the value of `minibuffer-history-variable'. However, the user didn't intend that the `hist' that is the value of `minibuffer-history-variable' be the `hist' that is passed as the parameter. Users of `my-completing-read', like users of `completing-read', expect to be able to pass any variable as the history variable. With `completing-read', they can, but not with `my-completing-read'. What is a clean way to work around the problem, to get the desired behavior? Simply changing the `hist' parameter name in `my-complete-read' is no help of course; then the problem just arises for the new name. Likewise, passing (set (make-symbol "foo") hist) as the HIST arg to `completing-read' is no help. A solution is to use a macro with an uninterned symbol: (defmacro my-completing-read (prompt table &optional predicate require-match initial-input hist def inherit-input-method) "" `(completing-read ,prompt ,table ,predicate ,require-match ,initial-input ,(set (make-symbol "foo") hist) ,def ,inherit-input-method)) That works, but I really need a function. Does anyone have a suggestion? Any help is appreciated, even an explanation that "you can't get there from here". If the latter is indeed the case, a second-best workaround would also be appreciated. All I can think of for that is to use an unlikely-to-capture name. Thx.