From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: miha--- via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#48925: [PATCH] Set `minibuffer-completion-*` variables buffer-locally in a few more places Date: Tue, 08 Jun 2021 20:30:29 +0200 Message-ID: <87fsxstdiy.fsf@miha-pc> Reply-To: miha@kamnitnik.top Mime-Version: 1.0 Content-Type: multipart/signed; boundary="==-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="2458"; mail-complaints-to="usenet@ciao.gmane.io" To: 48925@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Tue Jun 08 20:31:32 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 1lqgVf-0000Ti-Bf for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 08 Jun 2021 20:31:32 +0200 Original-Received: from localhost ([::1]:38244 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lqgVe-0003tp-DQ for geb-bug-gnu-emacs@m.gmane-mx.org; Tue, 08 Jun 2021 14:31:30 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60436) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqgVC-00032H-Oe for bug-gnu-emacs@gnu.org; Tue, 08 Jun 2021 14:31:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:48235) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lqgVC-0002gY-BP for bug-gnu-emacs@gnu.org; Tue, 08 Jun 2021 14:31:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lqgVC-0002rn-5k for bug-gnu-emacs@gnu.org; Tue, 08 Jun 2021 14:31:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: miha@kamnitnik.top Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 08 Jun 2021 18:31:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 48925 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.162317700910933 (code B ref -1); Tue, 08 Jun 2021 18:31:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 8 Jun 2021 18:30:09 +0000 Original-Received: from localhost ([127.0.0.1]:59777 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lqgUL-0002qH-5s for submit@debbugs.gnu.org; Tue, 08 Jun 2021 14:30:09 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:51838) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lqgUG-0002p6-1Z for submit@debbugs.gnu.org; Tue, 08 Jun 2021 14:30:07 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60244) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqgUF-0002LE-OT for bug-gnu-emacs@gnu.org; Tue, 08 Jun 2021 14:30:03 -0400 Original-Received: from kamnitnik.top ([2001:19f0:5001:bf2:5400:2ff:fee0:2626]:53452 helo=mail.kamnitnik.top) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lqgUD-0002LQ-6A for bug-gnu-emacs@gnu.org; Tue, 08 Jun 2021 14:30:03 -0400 Original-Received: from localhost (BSN-77-156-43.static.siol.net [193.77.156.43]) by mail.kamnitnik.top (Postfix) with ESMTPSA id 9DA0DBB843 for ; Tue, 8 Jun 2021 18:29:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kamnitnik.top; s=mail; t=1623176996; bh=Vf3ZDCrS+UtI7M7lfMHhMFbRhPVPthyE/dTmCJcNmMQ=; h=From:To:Subject:Date:From; b=fbyZJPoPdaPayhqhULhQBHP6mm7ccgtBBLtmqrockmfLx/xgL260eJ/U6ee59chnE 5TEp8rhaCHuU8l03GbCEsTG8hoNK5+zZjBzJylnIdV4y2B4cXn6ra1s7H0b47aDHp4 9VHPpGpl87HN+P6hZu+xtN8d1pBDCRZs+OaQqyYrf2PaqjNKve2sr90Imuv9Kkrhx1 vnn0UlInl/cGVbPigIWrRkCAAfLpRWBtXhe1rMu+1jR7qn1x8ic8eh7PB3hUwrNGfg QIH3qu89YZJr7fZOjLP037M7jCfyo6Y0D81LcHyRJbwpGpZnbdaBP7JSKwaaCKRJvW qLxBq1roxKOKg== Received-SPF: pass client-ip=2001:19f0:5001:bf2:5400:2ff:fee0:2626; envelope-from=miha@kamnitnik.top; helo=mail.kamnitnik.top X-Spam_score_int: 20 X-Spam_score: 2.0 X-Spam_bar: ++ X-Spam_report: (2.0 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FROM_SUSPICIOUS_NTLD=0.498, FROM_SUSPICIOUS_NTLD_FP=1.563, PDS_OTHER_BAD_TLD=1.997, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action 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:208259 Archived-At: --==-=-= Content-Type: multipart/mixed; boundary="=-=-=" --=-=-= Content-Type: text/plain This follows up on changes proposed in bug#45474. The second patch is a bit more controversial, but is probably required if we want more reliable usage of completion commands in non-innermost minibuffers (that is, with minibuffer-follows-selected-frame set to nil.) --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0001-Set-minibuffer-completion-variables-locally-in-more-.patch Content-Transfer-Encoding: quoted-printable From=20049d57e6d10edca1d6a0af119f557e364d8ea93f Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?Miha=3D20Rihtar=3DC5=3DA1i=3DC4=3D8D?=3D Date: Tue, 8 Jun 2021 20:17:59 +0200 Subject: [PATCH 1/2] Set `minibuffer-completion-*` variables locally in more places Follow-up to commit 2021-05-01 "* lisp/minibuffer.el (completing-read-default): Fix bug#45474" * lisp/calc/calc-store.el (calc-read-var-name): * lisp/emacs-lisp/crm.el (completing-read-multiple): * lisp/progmodes/cc-styles.el (c-read-offset): * lisp/window.el (read-buffer-to-switch): Set `minibuffer-completion-*` variables buffer-locally instead of using a global let-binding. =2D-- lisp/calc/calc-store.el | 15 +++++++----- lisp/emacs-lisp/crm.el | 47 ++++++++++++++++++------------------- lisp/progmodes/cc-styles.el | 12 ++++++---- lisp/window.el | 2 +- 4 files changed, 40 insertions(+), 36 deletions(-) diff --git a/lisp/calc/calc-store.el b/lisp/calc/calc-store.el index ee29c440fe..d96b40156d 100644 =2D-- a/lisp/calc/calc-store.el +++ b/lisp/calc/calc-store.el @@ -188,12 +188,15 @@ calc-read-var-name (let* ((calc-store-opers store-opers) (var (concat "var-" =2D (let ((minibuffer-completion-table =2D (mapcar (lambda (x) (substring x 4)) =2D (all-completions "var-" obarray))) =2D (minibuffer-completion-predicate =2D (lambda (x) (boundp (intern (concat "var-" x))))) =2D (minibuffer-completion-confirm t)) + (minibuffer-with-setup-hook + (lambda () + (setq-local minibuffer-completion-table + (mapcar (lambda (x) (substring x 4)) + (all-completions "var-" obarray))) + (setq-local minibuffer-completion-predicate + (lambda (x) + (boundp (intern (concat "var-" x))))) + (setq-local minibuffer-completion-confirm t)) (read-from-minibuffer prompt nil calc-var-name-map nil 'calc-read-var-name-history))))) diff --git a/lisp/emacs-lisp/crm.el b/lisp/emacs-lisp/crm.el index e106815817..67464bc6db 100644 =2D-- a/lisp/emacs-lisp/crm.el +++ b/lisp/emacs-lisp/crm.el @@ -245,30 +245,29 @@ completing-read-multiple =20 This function returns a list of the strings that were read, with empty strings removed." =2D (unwind-protect =2D (progn =2D (add-hook 'choose-completion-string-functions =2D 'crm--choose-completion-string) =2D (let* ((minibuffer-completion-table #'crm--collection-fn) =2D (minibuffer-completion-predicate predicate) =2D ;; see completing_read in src/minibuf.c =2D (minibuffer-completion-confirm =2D (unless (eq require-match t) require-match)) =2D (crm-completion-table table) =2D (map (if require-match =2D crm-local-must-match-map =2D crm-local-completion-map)) =2D ;; If the user enters empty input, `read-from-minibuffer' =2D ;; returns the empty string, not DEF. =2D (input (read-from-minibuffer =2D prompt initial-input map =2D nil hist def inherit-input-method))) =2D (when (and def (string-equal input "")) =2D (setq input (if (consp def) (car def) def))) =2D ;; Remove empty strings in the list of read strings. =2D (split-string input crm-separator t))) =2D (remove-hook 'choose-completion-string-functions =2D 'crm--choose-completion-string))) + (let* ((map (if require-match + crm-local-must-match-map + crm-local-completion-map)) + input) + (minibuffer-with-setup-hook + (lambda () + (add-hook 'choose-completion-string-functions + 'crm--choose-completion-string nil 'local) + (setq-local minibuffer-completion-table #'crm--collection-fn) + (setq-local minibuffer-completion-predicate predicate) + ;; see completing_read in src/minibuf.c + (setq-local minibuffer-completion-confirm + (unless (eq require-match t) require-match)) + (setq-local crm-completion-table table)) + (setq input (read-from-minibuffer + prompt initial-input map + nil hist def inherit-input-method))) + ;; If the user enters empty input, `read-from-minibuffer' + ;; returns the empty string, not DEF. + (when (and def (string-equal input "")) + (setq input (if (consp def) (car def) def))) + ;; Remove empty strings in the list of read strings. + (split-string input crm-separator t))) =20 ;; testing and debugging ;; (defun crm-init-test-environ () diff --git a/lisp/progmodes/cc-styles.el b/lisp/progmodes/cc-styles.el index 8514434e9a..873682043c 100644 =2D-- a/lisp/progmodes/cc-styles.el +++ b/lisp/progmodes/cc-styles.el @@ -444,17 +444,19 @@ c-read-offset defstr)) (prompt (concat symname " offset " defstr)) (keymap (make-sparse-keymap)) =2D (minibuffer-completion-table obarray) =2D (minibuffer-completion-predicate 'fboundp) offset input) ;; In principle completing-read is used here, but SPC is unbound ;; to make it less annoying to enter lists. (set-keymap-parent keymap minibuffer-local-completion-map) (define-key keymap " " 'self-insert-command) (while (not offset) =2D (setq input (read-from-minibuffer prompt nil keymap t =2D 'c-read-offset-history =2D (format "%s" oldoff))) + (minibuffer-with-setup-hook + (lambda () + (setq-local minibuffer-completion-table obarray) + (setq-local minibuffer-completion-predicate 'fboundp)) + (setq input (read-from-minibuffer prompt nil keymap t + 'c-read-offset-history + (format "%s" oldoff)))) (if (c-valid-offset input) (setq offset input) ;; error, but don't signal one, keep trying diff --git a/lisp/window.el b/lisp/window.el index fd1c617d6b..029202e350 100644 =2D-- a/lisp/window.el +++ b/lisp/window.el @@ -8376,7 +8376,7 @@ read-buffer-to-switch (let ((rbts-completion-table (internal-complete-buffer-except))) (minibuffer-with-setup-hook (lambda () =2D (setq minibuffer-completion-table rbts-completion-table) + (setq-local minibuffer-completion-table rbts-completion-table) ;; Since rbts-completion-table is built dynamically, we ;; can't just add it to the default value of ;; icomplete-with-completion-tables, so we add it =2D-=20 2.31.1 --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=0002-Don-t-bind-minibuffer-completion-table-to-nil-in-rea.patch Content-Transfer-Encoding: quoted-printable From=20466169b9f679a78aec00f9735335d90718c0d898 Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?Miha=3D20Rihtar=3DC5=3DA1i=3DC4=3D8D?=3D Date: Tue, 8 Jun 2021 20:19:44 +0200 Subject: [PATCH 2/2] Don't bind minibuffer-completion-table to nil in read-string This reverts 2012-06-19 "* src/minibuf.c (Fread_string): Bind minibuffer-completion-tabl= e." * src/minibuf.c (Fread_string): Don't bind minibuffer-completion-table to nil. =2D-- src/minibuf.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/minibuf.c b/src/minibuf.c index 00069eabbe..adee471887 100644 =2D-- a/src/minibuf.c +++ b/src/minibuf.c @@ -1376,20 +1376,13 @@ DEFUN ("read-string", Fread_string, Sread_string, 1= , 5, 0, (Lisp_Object prompt, Lisp_Object initial_input, Lisp_Object history, Lis= p_Object default_value, Lisp_Object inherit_input_method) { Lisp_Object val; =2D ptrdiff_t count =3D SPECPDL_INDEX (); =2D =2D /* Just in case we're in a recursive minibuffer, make it clear that the =2D previous minibuffer's completion table does not apply to the new =2D minibuffer. =2D FIXME: `minibuffer-completion-table' should be buffer-local instead= . */ =2D specbind (Qminibuffer_completion_table, Qnil); =20 val =3D Fread_from_minibuffer (prompt, initial_input, Qnil, Qnil, history, default_value, inherit_input_method); if (STRINGP (val) && SCHARS (val) =3D=3D 0 && ! NILP (default_value)) val =3D CONSP (default_value) ? XCAR (default_value) : default_value; =2D return unbind_to (count, val); + return val; } =20 DEFUN ("read-command", Fread_command, Sread_command, 1, 2, 0, =2D-=20 2.31.1 --=-=-=-- --==-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQJHBAEBCAAxFiEEmxVnesoT5rQXvVXnswkaGpIVmT8FAmC/t0UTHG1paGFAa2Ft bml0bmlrLnRvcAAKCRCzCRoakhWZP51vD/0T1qggVwg0fwCH2LRvjsB7G8UPwHmk LQQdscOkfSeJOFz0RI/0VI/rXXN2sV14/vB53EDwXSNKxlSzUY4DLyTcRVDTVVJt 8NhIGMeaXrCw75X5+Y+cSmlUaIIk7kOR+17d9bB8Z5Avoo43bpwzovkrbk3OHLj/ 8n+uH/KcLY+HDTef/ZUNoKi1tLofX3grB5OLkdWXw/1209Vx4l8fAhTbv2Ha6XA5 p7tayadbowQi9Gj+xl2EJ0t/OzqP57tGSvBzuB3/T9v6npdfT5gHC3jceAigoH0G CYalxm//DdTN+mIaXgu+pKrruGhAfX3AB1iaAHbRmaxn6mdHDjgObyFaAtR2dsK0 OXP74PNdkndOthKwAL94qUKiHJ/vr0hNNuc70unuwCumrtXnvUShNSvRoKBrxCTV lwbYh3VyApKXo24z1SJbfL/m71F1cdokJPNoihyQn2YqDpUzfnPub1eINv/kboac NjxYB1XQ0hrxsVUjEyhw4/823oh1nizyeVDAKrL1Good/qtiX0lhN2D94VM150+k 9bcHp8klHu70WJBiWqPCuHvsyPjb32ns69sgx6nr0aGOCjP88d5+P5wxoRV5mI1N JBgiw6N9BRJErjZIFatmULPcAW++/mk37udjur8UzJ2SU9LfhxObB6/hDKGw/hr/ Ol5oD+K2ZJ5GWQ== =UhWH -----END PGP SIGNATURE----- --==-=-=--