1

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"?

  • Dunno about for Helm, but for ordinary completing-read you just type aaa RET. The case you show uses lax completion (the REQUIRE-MATCH arg is absent, aka nil), so you can enter anything you want to: aaa, zz, whatever. – Drew Jun 3 '17 at 21:38
  • The problem is that aaa RET will return "aaaa" when using helm. I know I can use helm-comp-read and get the desired behavior programatically but I need this to work for 3rd party packages as well. In essence I am looking for a command to quit the helm buffer with currently typed input. – mkcms Jun 3 '17 at 22:20
1

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.