]> code.delx.au - gnu-emacs-elpa/commitdiff
Merge pull request #531 from juergenhoetzel/master
authorDmitry Gutov <dgutov@yandex.ru>
Sat, 11 Jun 2016 11:39:15 +0000 (14:39 +0300)
committerGitHub <noreply@github.com>
Sat, 11 Jun 2016 11:39:15 +0000 (14:39 +0300)
New transformer: company-sort-prefer-same-case-prefix

company.el

index 443e63819eb2490fa9189b63533ef1fbb8ee94a5..28ed56be3286e6ce640b75efdbc50323dd7d6a88 100644 (file)
@@ -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))