From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Dmitry Gutov Newsgroups: gmane.emacs.bugs Subject: bug#49204: 28.0.50; How to create new file in project by project-find-file Date: Mon, 2 Aug 2021 14:37:41 +0300 Message-ID: <49ce60bf-9c8d-818f-a0a4-4010a7e56462@yandex.ru> References: <6f475812-e088-f0e0-e01f-11cd643ff3e6@yandex.ru> <87k0lmqu8r.fsf@mail.linkov.net> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------40F1AA77ED132FAEA75CF8F7" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10328"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 Cc: Giap Tran , Stephen Leake , 49204@debbugs.gnu.org, Juri Linkov To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Aug 02 13:38:12 2021 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 1mAWGq-0002ZH-FB for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 02 Aug 2021 13:38:12 +0200 Original-Received: from localhost ([::1]:34708 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mAWGp-0003DW-6K for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 02 Aug 2021 07:38:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46420) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mAWGh-0003DC-3f for bug-gnu-emacs@gnu.org; Mon, 02 Aug 2021 07:38:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:54499) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mAWGg-0004dq-FH for bug-gnu-emacs@gnu.org; Mon, 02 Aug 2021 07:38:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mAWGg-0006rM-Cd for bug-gnu-emacs@gnu.org; Mon, 02 Aug 2021 07:38:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Dmitry Gutov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 02 Aug 2021 11:38:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 49204 X-GNU-PR-Package: emacs Original-Received: via spool by 49204-submit@debbugs.gnu.org id=B49204.162790427226351 (code B ref 49204); Mon, 02 Aug 2021 11:38:02 +0000 Original-Received: (at 49204) by debbugs.gnu.org; 2 Aug 2021 11:37:52 +0000 Original-Received: from localhost ([127.0.0.1]:37812 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mAWGV-0006qx-Hx for submit@debbugs.gnu.org; Mon, 02 Aug 2021 07:37:51 -0400 Original-Received: from mail-wr1-f50.google.com ([209.85.221.50]:34783) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mAWGU-0006qg-5J for 49204@debbugs.gnu.org; Mon, 02 Aug 2021 07:37:50 -0400 Original-Received: by mail-wr1-f50.google.com with SMTP id h13so7621950wrp.1 for <49204@debbugs.gnu.org>; Mon, 02 Aug 2021 04:37:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language; bh=97c0ha4EW7w15DYa7DtHPavp3PdS52kFk/dyMFFjp0I=; b=WAwZJQDl3hRvovv40XQCteJG3f9XJTYl+GgyBCQexWCG+IibcJat/wl1QNIVynUA63 kFcq+r2PP85gj+P72IqP1n9ofPdzR6ycHRX2XMsb+1y+csRWyrKqUUltQRySiyHsDc7k h60JwAk9/6ubxA/a3U2cePo9t+Os0S1Gyrc+4Wg5zg/eoNjlqOSQeV2oZ5townIFhEIB 0c0aun+dkAfS7JPRbg3X9tmqIFJYO0ESk85St+idnB6uQHAG92mFoOemaI+/UoyDEc0A XFYtYfI5yxbebq03+K0/B3ra6BuOh6tpRXtIgUnGpQZoME1BzuUCD2e+jh4wKXRC1dNf vngw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:cc:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language; bh=97c0ha4EW7w15DYa7DtHPavp3PdS52kFk/dyMFFjp0I=; b=h4bQCEZAHLBg539DbXuyDXI8SejDYSIEBoQIW54LEmgPMnEE1ktI5QhkEsYzr6QiZe 48sakGQIoE1eqAJrf6791Ns2oSzPn8WgHWfeOC83O7HQ4C5Q0dSAIcPeDV6MNeErKkCw /a7Vo7Zj257w/0UyH9L7D/mgR27sSrenW4dEf4Ptnuuu5DqxMzye38WQPNVkOF1MoQx5 1STpJ6yR6xPt5yQiEehyBm4NiWZEuVmPgnorY8i81M9B4ervhSABv/M83eIrv1yaikXO SvOJC9AidptGxFnUjgnbJutppOaUq/RzVHPnxlhfP7DIGkFJVXdEcIfOQCX77tapYbae w4sA== X-Gm-Message-State: AOAM5321XzaAGLxYiviGJE9ewLFjZ8wMzjy//cfGyQpsueyJYlxpH3Kd D7KuONDf7WViix6RvZ/Vll8= X-Google-Smtp-Source: ABdhPJz9AZwJxqcD6ELIiBCsnG1o8VCCXwRcyni3MberPGisV0wIfP8meAQ+o5FjycG/FvECpTYB/A== X-Received: by 2002:a5d:6b8f:: with SMTP id n15mr16822704wrx.103.1627904264281; Mon, 02 Aug 2021 04:37:44 -0700 (PDT) Original-Received: from [192.168.0.6] ([46.251.119.176]) by smtp.googlemail.com with ESMTPSA id 19sm3753806wmj.48.2021.08.02.04.37.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 02 Aug 2021 04:37:43 -0700 (PDT) In-Reply-To: Content-Language: en-US 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" Xref: news.gmane.io gmane.emacs.bugs:211067 Archived-At: This is a multi-part message in MIME format. --------------40F1AA77ED132FAEA75CF8F7 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit On 21.07.2021 04:34, Stefan Monnier via Bug reports for GNU Emacs, the Swiss army knife of text editors wrote: >>> I haven't followed the discussion, so I might be off, but I think what >>> is described above is something you can get simply by passing the >>> appropriate value for `mustmatch` to `completing-read` and friends >>> (including `read-file-name`). >> Probably not: most third-party completion functions out there don't support >> any non-nil values of that argument other than t (or treat them like t). > > Their loss. Actually, ivy-completing-read treats 'confirm' the same as nil. Oh well. >> And suppose we chose to use 'confirm', would a neutral prompt "Confirm" >> without clarification, as opposed to something like "File does not exist; >> Create?", be our best choice? > > The same question comes up for `C-x C-f` (and `C-x C-b`). > > So far the answer we have chosen is "yes". We can revisit it, > of course. Just like we may want to revisit the way `mustmatch` works, > but at least there is an existing "standard protocol" to get that kind > of behavior and I can't think of a good reason why `project-find-file` > should behave very differently from `find-file` in this respect. Fair enough. Trying this approach, I seem to recall the main problem we tried to solve originally: the string passed as DEFAULT was returned as the value entered by the user if they simply pressed RET, with no additional check for whether it actually matches any of the file names (or the "Confirm" prompt). The attached patch seems to solve that. Does the behavior look good to everyone? --------------40F1AA77ED132FAEA75CF8F7 Content-Type: text/x-patch; charset=UTF-8; name="project-find-file-confirm-non-match.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="project-find-file-confirm-non-match.diff" diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el index 0e73286426..6a330ecb2b 100644 --- a/lisp/progmodes/project.el +++ b/lisp/progmodes/project.el @@ -879,23 +879,16 @@ project-find-file-in (defun project--completing-read-strict (prompt collection &optional predicate hist default) - ;; Tried both expanding the default before showing the prompt, and - ;; removing it when it has no matches. Neither seems natural - ;; enough. Removal is confusing; early expansion makes the prompt - ;; too long. - (let* ((new-prompt (if (and default (not (string-equal default ""))) - (format "%s (default %s): " prompt default) - (format "%s: " prompt))) - (res (completing-read new-prompt - collection predicate t - nil ;; initial-input - hist default))) - (when (and (equal res default) - (not (test-completion res collection predicate))) - (setq res - (completing-read (format "%s: " prompt) - collection predicate t res hist nil))) - res)) + (minibuffer-with-setup-hook + (lambda () + (setq-local minibuffer-default-add-function + (lambda () + (let ((minibuffer-default default)) + (minibuffer-default-add-completions))))) + (completing-read prompt + collection predicate 'confirm + nil + hist))) ;;;###autoload (defun project-dired () --------------40F1AA77ED132FAEA75CF8F7--