Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handling completing-read-multiple #3014

Open
bymoz089 opened this issue Mar 9, 2023 · 0 comments
Open

handling completing-read-multiple #3014

bymoz089 opened this issue Mar 9, 2023 · 0 comments

Comments

@bymoz089
Copy link
Contributor

bymoz089 commented Mar 9, 2023

Currently ivy does not handle calls to completing-read-multiple. On those calls Emacs default completion system is used and ivy is utilized only when the user presses the TAB key. But the user has to remember that completing-read-multiple uses , (comma) to separate multiple choices.

How about utilizing ivy (or maybe that belongs into counsel?) on calls to completing-read-multiple right from the start and using ivy-mark feature to let the user choose multiple candidates?

There is no variable to configure invocations of completing-read-multiple in Emacs, like it is done with completing-read and completing-read-function. So an advice is needed. to wrap calls.

A working setup could look like that:

(defun ivy-completing-read-multiple-wrapper (fun prompt table &optional predicate require-match initial-input history def inherit-input-method)
  "a simple wrapper for advicing `completing-read-multiple'."
  (let (choices
        (new-prompt (concat "[multiple] " prompt))) ; just a hint for the user
    (ivy-read new-prompt table
              :predicate predicate
              :require-match require-match
              :initial-input initial-input
              :history history
              :def def
              :action (lambda (x)
                        (if (consp x)
                            (push (car x) choices)
                          (push x choices))))
    choices))

(advice-add 'completing-read-multiple :around #'ivy-completing-read-multiple-wrapper)

Test above functionality with (and compare it with unadviced completing-read-multiple):

(completing-read-multiple "select: "
                          '(("foo" . meh)
                            ("bar" (meeh meeeh))
                            ("moo" . meeeeh))
                          nil
                          t)
;; ⇒ ("moo" "bar")

(completing-read-multiple "select: "
                          '("foo"
                            "bar"
                            "moo")
                          nil
                          t)

;; ⇒ ("moo" "bar")

Is there interest in an PR?

@bymoz089 bymoz089 changed the title handling ompleting-read-multiple` handling completing-read-multiple Mar 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant