From 247b6f5cdac424f0a0bc96e01f9531709006faea Mon Sep 17 00:00:00 2001 From: Joe Junior Date: Sun, 28 Mar 2021 03:42:24 -0300 Subject: [PATCH 1/3] Fix for issue #2805 by using company-finish on counsel-company. --- counsel.el | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/counsel.el b/counsel.el index e5615173..ae8551fe 100644 --- a/counsel.el +++ b/counsel.el @@ -380,12 +380,12 @@ Update the minibuffer with the amount of lines collected every (setq ivy-completion-beg (- (point) len)) (setq ivy-completion-end (point)) (ivy-read "Candidate: " company-candidates - :action #'ivy-completion-in-region-action + :action 'company-finish :caller 'counsel-company)))) (ivy-configure 'counsel-company :display-transformer-fn #'counsel--company-display-transformer - :unwind-fn #'company-abort) + :unwind-fn (lambda() (unless ivy-exit (company-abort)))) (defun counsel--company-display-transformer (s) (concat s (let ((annot (company-call-backend 'annotation s))) From ceda444806985e45f173ffc72ad839e2d87b9c1e Mon Sep 17 00:00:00 2001 From: Joe Junior Date: Sun, 28 Mar 2021 18:10:26 -0300 Subject: [PATCH 2/3] Fix company-prefix and company-common when using counsel-company. The company-common is always downcase, even when the prefix might not be. This fix allows counsel-company to use company-common even when the prefix has uppercase letters. It also sets company-prefix to be equal to company-common, without this, company-finish does not know that the prefix was expanded, and does not correctly removes the prefix from the candidate, generating duplicated characters. --- counsel.el | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/counsel.el b/counsel.el index ae8551fe..0d3bcd9e 100644 --- a/counsel.el +++ b/counsel.el @@ -370,9 +370,11 @@ Update the minibuffer with the amount of lines collected every (let ((len (cond ((let (l) (and company-common (string= company-common - (buffer-substring - (- (point) (setq l (length company-common))) - (point))) + (downcase + (buffer-substring + (- (point) (setq l (length company-common))) + (point)))) + (setq company-prefix company-common) l))) (company-prefix (length company-prefix))))) From 3dff6061af4ac3615be0541a4d5411170c412e9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20J=C3=BAnior?= Date: Tue, 30 Mar 2021 22:17:48 -0300 Subject: [PATCH 3/3] Refactored counsel-company simplifying and removing uneeded code. --- counsel.el | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/counsel.el b/counsel.el index 0d3bcd9e..f47707ae 100644 --- a/counsel.el +++ b/counsel.el @@ -367,23 +367,11 @@ Update the minibuffer with the amount of lines collected every (company-mode 1) (unless company-candidates (company-complete)) - (let ((len (cond ((let (l) - (and company-common - (string= company-common - (downcase - (buffer-substring - (- (point) (setq l (length company-common))) - (point)))) - (setq company-prefix company-common) - l))) - (company-prefix - (length company-prefix))))) - (when len - (setq ivy-completion-beg (- (point) len)) - (setq ivy-completion-end (point)) - (ivy-read "Candidate: " company-candidates - :action 'company-finish - :caller 'counsel-company)))) + (company--continue) + (when company-candidates + (ivy-read "Candidate: " company-candidates + :action 'company-finish + :caller 'counsel-company))) (ivy-configure 'counsel-company :display-transformer-fn #'counsel--company-display-transformer