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

counsel-company now automatically selects its candidate if there is only one choice #2849

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions counsel.el
Original file line number Diff line number Diff line change
Expand Up @@ -379,9 +379,13 @@ Update the minibuffer with the amount of lines collected every
(when len
(setq ivy-completion-beg (- (point) len))
(setq ivy-completion-end (point))
(ivy-read "Candidate: " company-candidates
:action #'ivy-completion-in-region-action
:caller 'counsel-company))))
(cond
((= (length company-candidates) 1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: If company-candidates is a list, it's better to say:

(and company-candidates
     (null (cdr company-candidates)))

to avoid traversing the entire list. In Emacs 28, you can alternatively say:

(length= company-candidates 1)

Not sure if it's worth writing a compatibility shim for this.

(ivy-completion-in-region-action (car company-candidates))
)
(t (ivy-read "Candidate: " company-candidates
:action #'ivy-completion-in-region-action
:caller 'counsel-company))))))
Comment on lines +385 to +388
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: there's a trailing paren and the indentation seems off. Suggest to simplify:

(if (cdr company-candidates)
    (ivy-read "Candidate: " company-candidates
              :action #'ivy-completion-in-region-action
              :caller 'counsel-company)
  (ivy-completion-in-region-action (car company-candidates)))


(ivy-configure 'counsel-company
:display-transformer-fn #'counsel--company-display-transformer
Expand Down