summaryrefslogtreecommitdiff
path: root/helm-mode.el
diff options
context:
space:
mode:
authorThierry Volpiatto <thievol@posteo.net>2020-09-05 08:43:49 +0200
committerThierry Volpiatto <thievol@posteo.net>2020-09-05 08:43:49 +0200
commited314ff2c463f1c56dc102ffb6075878b39e535f (patch)
tree4f9b464a79af00a97712c7a043d51df6079df900 /helm-mode.el
parent6c24f1972806a31263de87e117464a8a1a81f2fe (diff)
Fix read-buffer by using minibuffer-completion-table
Try to use minibuffer-completion-table if it is bound otherwise fallback to internal-complete-buffer. The problem is that the definition of read-buffer-to-switch is wrong, as it pass minibuffer-completion-table only through minibuffer-setup-hook which is too late for helm and other backends used as read-buffer-function, so advise read-buffer-to-switch from helm-mode.
Diffstat (limited to 'helm-mode.el')
-rw-r--r--helm-mode.el25
1 files changed, 16 insertions, 9 deletions
diff --git a/helm-mode.el b/helm-mode.el
index 92a3570b..bb9a1f8b 100644
--- a/helm-mode.el
+++ b/helm-mode.el
@@ -513,7 +513,10 @@ If COLLECTION is an `obarray', a TEST should be needed. See `obarray'."
;; Don't convert
;; nil to "nil" (i.e the string)
;; it will be delq'ed on top.
- collect (if (null d) d (helm-stringify d)))
+ for str = (if (null d) d (helm-stringify d))
+ when (member str cands)
+ do (setq cands (delete d cands))
+ when str collect str)
cands))
(t cands))))
@@ -1048,16 +1051,18 @@ This handler uses dynamic matching which allows honouring `completion-styles'."
init hist default inherit-input-method
name buffer standard)))
+(defun helm-read-buffer-to-switch (prompt)
+ (let ((minibuffer-completion-table (internal-complete-buffer-except)))
+ (read-buffer prompt (other-buffer (current-buffer))
+ (confirm-nonexistent-file-or-buffer))))
+
(defun helm--generic-read-buffer (prompt &optional default require-match predicate)
"The `read-buffer-function' for `helm-mode'.
Affects `switch-to-buffer' `kill-buffer' and related."
- ;; Use `internal-complete-buffer-except' as default collection,
- ;; assuming `switch-to-buffer' doesn't need the current buffer and
- ;; `kill-buffer' add it on top of completion list. This may be
- ;; wrong in other functions, but lets use this as there is no better
- ;; solutions to abstract this for now.
(helm--completing-read-default
- prompt (internal-complete-buffer-except) predicate require-match nil nil default))
+ prompt (or minibuffer-completion-table
+ (internal-complete-buffer "" nil t))
+ predicate require-match nil nil default))
(cl-defun helm--completing-read-default
(prompt collection &optional
@@ -2015,7 +2020,8 @@ Note: This mode is incompatible with Emacs23."
;; `ffap-read-file-or-url-internal' have been removed in
;; emacs-27 and `ffap-read-file-or-url' is fixed, so no need
;; to advice it.
- (advice-add 'ffap-read-file-or-url :override #'helm-advice--ffap-read-file-or-url)))
+ (advice-add 'ffap-read-file-or-url :override #'helm-advice--ffap-read-file-or-url))
+ (advice-add 'read-buffer-to-switch :override #'helm-read-buffer-to-switch))
(progn
(remove-function completing-read-function #'helm--completing-read-default)
(remove-function read-file-name-function #'helm--generic-read-file-name)
@@ -2023,7 +2029,8 @@ Note: This mode is incompatible with Emacs23."
(remove-function completion-in-region-function #'helm--completion-in-region)
(remove-hook 'ido-everywhere-hook #'helm-mode--ido-everywhere-hook)
(when (fboundp 'ffap-read-file-or-url-internal)
- (advice-remove 'ffap-read-file-or-url #'helm-advice--ffap-read-file-or-url)))))
+ (advice-remove 'ffap-read-file-or-url #'helm-advice--ffap-read-file-or-url))
+ (advice-remove 'read-buffer-to-switch #'helm-read-buffer-to-switch))))
(provide 'helm-mode)