In helm, when executing following code:
(let ((things (list "a" "aa" "aaaa")))
(completing-read "Thing: " things))
... how can I exit the minibuffer and return "aaa"
?
In helm, when executing following code:
(let ((things (list "a" "aa" "aaaa")))
(completing-read "Thing: " things))
... how can I exit the minibuffer and return "aaa"
?
EDIT: This issue was fixed in helm on June 6th, 2017. See commit 09b6fcd.
After hours spent on searching it seems to me that helm forces matching input with completing-read
, so I wrote my own command to quit helm sessions without matching. It allows exiting helm sessions with whatever is in the minibuffer via M-#
and works by advising completing-read
.
(defvar accepted-minibuffer-contents nil
"Minibuffer contents saved in `force-exit-minibuffer-now'.")
(defun force-exit-minibuffer-now ()
"Exit minibuffer (successfully) with whatever contents are in it.
Exiting helm sessions via this function doesn't attempt to match
the minibuffer contents with candidates supplied to `completing-read'."
(interactive)
(if minibuffer-completion-confirm
(minibuffer-complete-and-exit)
(setq accepted-minibuffer-contents (minibuffer-contents))
(exit-minibuffer)))
(define-key helm-map (kbd "M-#") 'force-exit-minibuffer-now)
(defun my-completing-read (orig-fn &rest args)
(interactive)
(let* ((accepted-minibuffer-contents nil)
(result (apply orig-fn args)))
(or accepted-minibuffer-contents result)))
(advice-add 'completing-read :around 'my-completing-read)