]> git.eshelyaron.com Git - emacs.git/commitdiff
Set `minibuffer-completion-*` variables locally in more places
authorMiha Rihtaršič <miha@kamnitnik.top>
Thu, 11 Nov 2021 05:16:52 +0000 (06:16 +0100)
committerLars Ingebrigtsen <larsi@gnus.org>
Thu, 11 Nov 2021 05:16:52 +0000 (06:16 +0100)
* 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 (bug#48925).

Follow-up to commit
2021-05-01 "* lisp/minibuffer.el (completing-read-default): Fix bug#45474"

lisp/calc/calc-store.el
lisp/emacs-lisp/crm.el
lisp/progmodes/cc-styles.el
lisp/window.el

index b3968555b6291d5d101b2f8c24b6b826c32b7930..de2f18f39479acdee8d8e6625400f37b9847c692 100644 (file)
   (let* ((calc-store-opers store-opers)
          (var (concat
               "var-"
-              (let ((minibuffer-completion-table
-                     (mapcar (lambda (x) (substring x 4))
-                             (all-completions "var-" obarray)))
-                    (minibuffer-completion-predicate
-                     (lambda (x) (boundp (intern (concat "var-" x)))))
-                    (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)))))
index d24ea355a51df93b55721838a9fc0213690cdd65..59cbc0e50d5b35321df1612b7ac4683a482f8064 100644 (file)
@@ -244,30 +244,29 @@ contents of the minibuffer are \"alice,bob,eve\" and point is between
 
 This function returns a list of the strings that were read,
 with empty strings removed."
-  (unwind-protect
-      (progn
-       (add-hook 'choose-completion-string-functions
-                 'crm--choose-completion-string)
-       (let* ((minibuffer-completion-table #'crm--collection-fn)
-              (minibuffer-completion-predicate predicate)
-              ;; see completing_read in src/minibuf.c
-              (minibuffer-completion-confirm
-               (unless (eq require-match t) require-match))
-              (crm-completion-table table)
-              (map (if require-match
-                       crm-local-must-match-map
-                     crm-local-completion-map))
-              ;; If the user enters empty input, `read-from-minibuffer'
-              ;; returns the empty string, not DEF.
-              (input (read-from-minibuffer
-                      prompt initial-input map
-                      nil hist def inherit-input-method)))
-         (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)))
-    (remove-hook 'choose-completion-string-functions
-                '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)))
 
 ;; testing and debugging
 ;; (defun crm-init-test-environ ()
index c6b6be5b3991369d729dd42109bf5fb8e952ee02..4d518838d11f2fd2bd9fe63aaf429cc150ba36a6 100644 (file)
@@ -444,17 +444,19 @@ STYLE using `c-set-style' if the optional SET-P flag is non-nil."
                          defstr))
         (prompt (concat symname " offset " defstr))
         (keymap (make-sparse-keymap))
-        (minibuffer-completion-table obarray)
-        (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)
-      (setq input (read-from-minibuffer prompt nil keymap t
-                                       'c-read-offset-history
-                                       (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
index 25827436795ced570ad3f0b2f873ee697e84086b..0f17bb28b4c460e60377af9410685feeda1d24fe 100644 (file)
@@ -8574,7 +8574,7 @@ from the list of completions and default values."
   (let ((rbts-completion-table (internal-complete-buffer-except)))
     (minibuffer-with-setup-hook
         (lambda ()
-          (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