From b8f877703a0d50b46254fcfee3c815ae5e386013 Mon Sep 17 00:00:00 2001 From: Juergen Hoetzel Date: Sat, 4 Jun 2016 10:06:32 +0200 Subject: [PATCH] New transformer: company-sort-prefer-same-case-prefix --- company.el | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/company.el b/company.el index 443e63819..28ed56be3 100644 --- a/company.el +++ b/company.el @@ -465,6 +465,8 @@ without duplicates." (const :tag "Sort by occurrence" (company-sort-by-occurrence)) (const :tag "Sort by backend importance" (company-sort-by-backend-importance)) + (const :tag "Prefer case sensitive prefix" + (company-sort-prefer-same-case-prefix)) (repeat :tag "User defined" (function)))) (defcustom company-completion-started-hook nil @@ -1331,6 +1333,16 @@ from the rest of the backends in the group, if any, will be left at the end." (let ((b1 (get-text-property 0 'company-backend c1))) (or (not b1) (not (memq b1 low-priority))))))))))) +(defun company-sort-prefer-same-case-prefix (candidates) + "Prefer CANDIDATES with the same case sensitive prefix. +If a backend returns case insensitive matches, candidates with the an exact +prefix match will be prioritized even if this changes the lexical order." + (cl-loop for candidate in candidates + if (string-prefix-p company-prefix candidate) + collect candidate into same-case + else collect candidate into other-case + finally return (append same-case other-case))) + (defun company-idle-begin (buf win tick pos) (and (eq buf (current-buffer)) (eq win (selected-window)) -- 2.39.2