From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#65459: completing-read INITIAL-VALUE unaware of COLLECTION and REQUIRE-MATCH Date: Thu, 24 Aug 2023 09:46:46 -0400 Message-ID: References: <83jztmro8z.fsf@gnu.org> Reply-To: Stefan Monnier Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="32134"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Heime , Eli Zaretskii , 65459@debbugs.gnu.org To: Gregory Heytings Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Aug 24 15:48:13 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qZAh3-00087W-7J for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 24 Aug 2023 15:48:13 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qZAgp-00045t-Tu; Thu, 24 Aug 2023 09:47:59 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qZAgo-00045d-FT for bug-gnu-emacs@gnu.org; Thu, 24 Aug 2023 09:47:58 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qZAgo-0008CO-7A for bug-gnu-emacs@gnu.org; Thu, 24 Aug 2023 09:47:58 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qZAgr-0006Ip-Ue for bug-gnu-emacs@gnu.org; Thu, 24 Aug 2023 09:48:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stefan Monnier Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 24 Aug 2023 13:48:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 65459 X-GNU-PR-Package: emacs Original-Received: via spool by 65459-submit@debbugs.gnu.org id=B65459.169288482424038 (code B ref 65459); Thu, 24 Aug 2023 13:48:01 +0000 Original-Received: (at 65459) by debbugs.gnu.org; 24 Aug 2023 13:47:04 +0000 Original-Received: from localhost ([127.0.0.1]:36408 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qZAfw-0006Fe-HF for submit@debbugs.gnu.org; Thu, 24 Aug 2023 09:47:04 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:33977) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qZAfu-0006F9-Dj for 65459@debbugs.gnu.org; Thu, 24 Aug 2023 09:47:02 -0400 Original-Received: from pmg1.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id B4E5E1000BD; Thu, 24 Aug 2023 09:46:52 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1692884807; bh=EudCX1htd2cFEBaY+civoDTezBT5AhXLnoOJhkMn+S4=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=eYCBtxcDQ29Ckb8PKQDOBCEwcq4K6CmhQ9acHnK3SsZWc+JGAMPJCe5rMLvlXpg/n M96g4m90YhgOkn0MAynuzYvRX0wwM1EqaNYtI/HCLDr9gh8ExVVvdKrwqi4hkY2ymM Hby1fxN7GGigGRMMtakWwl+hbslJ4G9snwOkroz6+hH/rKROQyXg4EOQzGV+b//6yG 9RmiK97N+V/Lvu40eo1mPYVI6uLjA9cy2yD9EQhZNLwWyGAKMQIY8lTZ9vIdmKwkSZ nT0j7OrVavQ6QuQrllj9oC1cjM71SGjBAirXSipS8KTzBS7P/bpjeG1uUlxExQIhgA H5HCXNPCBDIxQ== Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg1.iro.umontreal.ca (Proxmox) with ESMTP id 33DDC100084; Thu, 24 Aug 2023 09:46:47 -0400 (EDT) Original-Received: from pastel (unknown [104.247.227.249]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 0CE021201A6; Thu, 24 Aug 2023 09:46:47 -0400 (EDT) In-Reply-To: (Gregory Heytings's message of "Thu, 24 Aug 2023 12:30:51 +0000") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:268340 Archived-At: >>> (defun my-completing-read (prompt collection start) >>> (minibuffer-with-setup-hook >>> (:append >>> (lambda () >>> (setq-local actual-minibuffer-default-add-function >>> minibuffer-default-add-function) >>> (setq-local minibuffer-default-add-function >>> '(lambda () (setq minibuffer-default-add-done nil) >>> (funcall actual-minibuffer-default-add-function))) >> >> Why use ' on `lambda`? >> > > I think my finger slipped. > >> >> BTW, rather than the above two `setq-local`s, I think you can write: >> >> (add-function :before (local 'minibuffer-default-add-function) >> (lambda () (setq minibuffer-default-add-done nil))) >> > > Right. I was writing that function as it if were for minibuffer.el, and was > therefore avoiding advices. But now I see that there are a couple of > add-function in core anyway (it's not clear to me where the dividing line > is). So here's the final version: The issue is not "don't use `(n)advice.el`", but "don't modify functions on the sly". And by "functions" this refers to those things stored in the `symbol-function` slot of symbols in the global obarray. This is because code that does `(my-foo ...)` usually expects to execute the code found in `(defun my-foo ...)` and not something else, and readers of that code often make the same assumption, so it can make debugging really nasty. Changing a function with `fset` (or `cl-letf` or `defalias`) is worse than using `advice-add`, for that reason: at least `advice-add` sets up the help system such that `C-h f` will (hopefully) warn you about the presence of an advice. For variables containing functions (such as `minibuffer-default-add-function`), there is no such expectation that calling this function will run some known piece of code, on the contrary: the whole point of the variable is to run difference pieces of code in different contexts, so modifying the function is perfectly OK, regardless whether you do it with `setq` or `add-function`. Here I'd use `add-function` because it's simpler. Stefan