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

Can I complete and then immediately launch a new ivy completion? #596

Closed
benmaughan opened this Issue Jul 22, 2016 · 2 comments

Comments

Projects
None yet
2 participants
@benmaughan

benmaughan commented Jul 22, 2016

I use ivy to complete email addresses in mu4e, and at the moment, if I want to add multiple addresses, I use RET to complete the current address, then insert a comma and manually start a new completion. I'd like to adapt this so that I can hit comma at the ivy prompt it will complete the current selection, inserting the selected address and a comma in the buffer, and then clear the ivy filter in the minibuffer so I can start typing a new address. This emulates the address completion in e.g. thunderbird and gmail.

Any suggestions would be greatly appreciated!

My current code is described here
http://pragmaticemacs.com/emacs/tweaking-email-contact-completion-in-mu4e/

@abo-abo

This comment has been minimized.

Show comment
Hide comment
@abo-abo

abo-abo Jul 23, 2016

Owner

Here's a template for implementing what you want:

(defvar contacts '("gandalf@whitecastle.com"
                   "frodo@gmail.com"
                   "aragorn@gondor.gov"))

(defun counsel-email-action (x)
  (with-ivy-window
    (insert x)))

(defvar counsel-email-map
  (let ((map (make-sparse-keymap)))
    (define-key map "," 'counsel-email-more)
    map))

(defun counsel-email-more ()
  (interactive)
  (ivy-call)
  (with-ivy-window
    (insert ", "))
  (delete-minibuffer-contents)
  (setq ivy-text ""))

(defun counsel-email ()
  (interactive)
  (ivy-read "email: " contacts
            :action 'counsel-email-action
            :keymap counsel-email-map))

Pressing RET inserts an email and exits. Pressing , inserts and email and a comma, and clears the current input.

Owner

abo-abo commented Jul 23, 2016

Here's a template for implementing what you want:

(defvar contacts '("gandalf@whitecastle.com"
                   "frodo@gmail.com"
                   "aragorn@gondor.gov"))

(defun counsel-email-action (x)
  (with-ivy-window
    (insert x)))

(defvar counsel-email-map
  (let ((map (make-sparse-keymap)))
    (define-key map "," 'counsel-email-more)
    map))

(defun counsel-email-more ()
  (interactive)
  (ivy-call)
  (with-ivy-window
    (insert ", "))
  (delete-minibuffer-contents)
  (setq ivy-text ""))

(defun counsel-email ()
  (interactive)
  (ivy-read "email: " contacts
            :action 'counsel-email-action
            :keymap counsel-email-map))

Pressing RET inserts an email and exits. Pressing , inserts and email and a comma, and clears the current input.

@benmaughan

This comment has been minimized.

Show comment
Hide comment
@benmaughan

benmaughan Aug 11, 2016

Thanks - this is exactly what I needed to build my solution.

benmaughan commented Aug 11, 2016

Thanks - this is exactly what I needed to build my solution.

@benmaughan benmaughan closed this Aug 11, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment