branch: elpa/helm commit 7c2f08063910ef15a63cd58e6db0ffa2e4ddc12d Author: Thierry Volpiatto <thie...@posteo.net> Commit: Thierry Volpiatto <thie...@posteo.net>
Disable `minibuffer-complete' only for handlers using helm (bug #2533) --- helm-mode.el | 115 ++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 62 insertions(+), 53 deletions(-) diff --git a/helm-mode.el b/helm-mode.el index 701aee8de4..9d2e674d63 100644 --- a/helm-mode.el +++ b/helm-mode.el @@ -1184,6 +1184,18 @@ Affects `switch-to-buffer' `kill-buffer' and related." (t it)) val))) +(defun helm-mode--apply-helm-handler (handler arg-list) + "Ensure `minibuffer-complete' is disabled when running HANDLER. +ARG-LIST is a list of arguments to pass to HANDLER." + ;; Some functions are calling `minibuffer-complete' + ;; within `minibuffer-setup-hook' when calling their + ;; `completing-read', like `woman-file-name' (bug #2527). + ;; This defeat Helm which is already + ;; completing minibuffer, so deactivate + ;; minibuffer-complete one time for all [1]. + (cl-letf (((symbol-function 'minibuffer-complete) #'ignore)) + (apply handler arg-list))) + (cl-defun helm--completing-read-default (prompt collection &optional predicate require-match @@ -1238,59 +1250,56 @@ See documentation of `completing-read' and `all-completions' for details." ;; helm-completing-read-handlers-alist use default ;; handler. #'helm-completing-read-default-handler)) - ;; Some functions are calling `minibuffer-complete' within - ;; `minibuffer-setup-hook' when calling their `completing-read', - ;; like `woman-file-name' (bug #2527). This defeat Helm which is - ;; already completing minibuffer, so deactivate - ;; minibuffer-complete one time for all. - (cl-letf (((symbol-function 'minibuffer-complete) #'ignore)) - (when (eq def-com 'ido) (setq def-com 'ido-completing-read)) - (unless (or (not entry) def-com) - ;; An entry in *read-handlers-alist exists but have - ;; a nil value, so we exit from here, disable `helm-mode' - ;; and run the command again with it original behavior. - ;; `helm-mode' will be restored on exit. - (cl-return-from helm--completing-read-default - (unwind-protect - (progn - (helm-mode -1) - (apply completing-read-function def-args)) - (helm-mode 1)))) - ;; If we use now `completing-read' we MUST turn off `helm-mode' - ;; to avoid infinite recursion and CRASH. It will be reenabled on exit. - (when (or (eq def-com 'completing-read) - ;; All specialized functions are prefixed by "helm" - (and (stringp str-defcom) - (not (string-match "^helm" str-defcom)))) - (helm-mode -1)) - (unwind-protect - (cond (;; An helm specialized function exists, run it. - (and def-com helm-mode) - (apply def-com others-args)) - (;; Try to handle `ido-completing-read' everywhere. - (and def-com (eq def-com 'ido-completing-read)) - (setcar (memq collection def-args) - (all-completions "" collection predicate)) - (apply def-com def-args)) - (;; User set explicitely `completing-read' or something similar - ;; in *read-handlers-alist, use this with exactly the same - ;; args as in `completing-read'. - ;; If we are here `helm-mode' is now disabled. - def-com - (apply def-com def-args)) - (;; Use by default a in-buffer handler unless - ;; COLLECTION is a function. - t - (funcall default-handler - prompt collection predicate require-match - initial-input hist def inherit-input-method - str-command buf-name))) - (helm-mode 1) - ;; When exiting minibuffer, `this-command' is set to - ;; `helm-exit-minibuffer', which is unwanted when starting - ;; on another `completing-read', so restore `this-command' to - ;; initial value when exiting. - (setq this-command current-command))))) + (when (eq def-com 'ido) (setq def-com 'ido-completing-read)) + (unless (or (not entry) def-com) + ;; An entry in *read-handlers-alist exists but have + ;; a nil value, so we exit from here, disable `helm-mode' + ;; and run the command again with it original behavior. + ;; `helm-mode' will be restored on exit. + (cl-return-from helm--completing-read-default + (unwind-protect + (progn + (helm-mode -1) + (apply completing-read-function def-args)) + (helm-mode 1)))) + ;; If we use now `completing-read' we MUST turn off `helm-mode' + ;; to avoid infinite recursion and CRASH. It will be reenabled on exit. + (when (or (eq def-com 'completing-read) + ;; All specialized functions are prefixed by "helm" + (and (stringp str-defcom) + (not (string-match "^helm" str-defcom)))) + (helm-mode -1)) + (unwind-protect + (cond (;; An helm specialized function exists, run it. + (and def-com helm-mode) + ;; Disable `minibuffer-complete' for handlers using + ;; helm (bug #2533). + (helm-mode--apply-helm-handler + def-com others-args)) + (;; Try to handle `ido-completing-read' everywhere. + (and def-com (eq def-com 'ido-completing-read)) + (setcar (memq collection def-args) + (all-completions "" collection predicate)) + (apply def-com def-args)) + (;; A non helm function specified in + ;; `helm-completing-read-handlers-alist' use it with + ;; exactly the same args as in `completing-read'. If + ;; we are here `helm-mode' is now disabled. + def-com + (apply def-com def-args)) + (;; Use by default a in-buffer handler unless + ;; COLLECTION is a function. + t + ;; Disable `minibuffer-complete' for handlers using + ;; helm (bug #2533). + (helm-mode--apply-helm-handler + default-handler others-args))) + (helm-mode 1) + ;; When exiting minibuffer, `this-command' is set to + ;; `helm-exit-minibuffer', which is unwanted when starting + ;; on another `completing-read', so restore `this-command' to + ;; initial value when exiting. + (setq this-command current-command)))) ;;; Generic read-file-name ;;