[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 201577c 01/31: Begin completion on a unique match if the u
From: |
Dmitry Gutov |
Subject: |
[elpa] master 201577c 01/31: Begin completion on a unique match if the user really wants that |
Date: |
Sun, 14 Apr 2019 22:06:14 -0400 (EDT) |
branch: master
commit 201577cd7ca815b8be2dc62e1f433ee12c1d654f
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>
Begin completion on a unique match if the user really wants that
Called with M-x company-complete, it will immediately finish, of course, and
trigger post-completion hooks.
#150 #476
---
company.el | 63 +++++++++++++++++++++++++++++++-------------------------------
1 file changed, 32 insertions(+), 31 deletions(-)
diff --git a/company.el b/company.el
index 5676583..a1e72ab 100644
--- a/company.el
+++ b/company.el
@@ -1202,9 +1202,8 @@ can retrieve meta-data for them."
common))
(car company-candidates)))))
-(defun company-calculate-candidates (prefix)
- (let ((candidates (cdr (assoc prefix company-candidates-cache)))
- (ignore-case (company-call-backend 'ignore-case)))
+(defun company-calculate-candidates (prefix ignore-case)
+ (let ((candidates (cdr (assoc prefix company-candidates-cache))))
(or candidates
(when company-candidates-cache
(let ((len (length prefix))
@@ -1222,14 +1221,13 @@ can retrieve meta-data for them."
;; Save in cache.
(push (cons prefix candidates) company-candidates-cache)))
;; Only now apply the predicate and transformers.
- (setq candidates (company--postprocess-candidates candidates))
- (when candidates
- (if (or (cdr candidates)
- (not (eq t (compare-strings (car candidates) nil nil
- prefix nil nil ignore-case))))
- candidates
- ;; Already completed and unique; don't start.
- t))))
+ (company--postprocess-candidates candidates)))
+
+(defun company--unique-match-p (candidates prefix ignore-case)
+ (and candidates
+ (not (cdr candidates))
+ (eq t (compare-strings (car candidates) nil nil
+ prefix nil nil ignore-case))))
(defun company--fetch-candidates (prefix)
(let* ((non-essential (not (company-explicit-action-p)))
@@ -1533,14 +1531,14 @@ prefix match (same case) will be prioritized."
;; Don't complete existing candidates, fetch new ones.
(setq company-candidates-cache nil))
(let* ((new-prefix (company-call-backend 'prefix))
+ (ignore-case (company-call-backend 'ignore-case))
(c (when (and (company--good-prefix-p new-prefix)
(setq new-prefix (company--prefix-str new-prefix))
(= (- (point) (length new-prefix))
(- company-point (length company-prefix))))
- (company-calculate-candidates new-prefix))))
+ (company-calculate-candidates new-prefix ignore-case))))
(cond
- ((eq c t)
- ;; t means complete/unique.
+ ((company--unique-match-p c new-prefix ignore-case)
;; Handle it like completion was aborted, to differentiate from user
;; calling one of Company's commands to insert the candidate,
;; not to trigger template expansion, etc.
@@ -1578,23 +1576,26 @@ prefix match (same case) will be prioritized."
(company--multi-backend-adapter backend 'prefix)))
(when prefix
(when (company--good-prefix-p prefix)
- (setq company-prefix (company--prefix-str prefix)
- company-backend backend
- c (company-calculate-candidates company-prefix))
- (if (not (consp c))
- (progn
- (when company--manual-action
- (message "No completion found"))
- (when (eq c t)
- ;; t means complete/unique.
- ;; Run the hooks anyway, to e.g. clear the cache.
- (company-cancel 'unique)))
- (when company--manual-action
- (setq company--manual-prefix prefix))
- (company-update-candidates c)
- (run-hook-with-args 'company-completion-started-hook
- (company-explicit-action-p))
- (company-call-frontends 'show)))
+ (let ((ignore-case (company-call-backend 'ignore-case)))
+ (setq company-prefix (company--prefix-str prefix)
+ company-backend backend
+ c (company-calculate-candidates company-prefix ignore-case))
+ (cond
+ ((and (not company--manual-action)
+ ;; If `company-manual-begin' was called, the user
+ ;; really wants something to happen. Otherwise...
+ (company--unique-match-p c company-prefix ignore-case))
+ ;; ...abort and run the hooks, e.g. to clear the cache.
+ (company-cancel 'unique))
+ ((and (null c) company--manual-action)
+ (message "No completion found"))
+ (t ;; We got completions!
+ (when company--manual-action
+ (setq company--manual-prefix prefix))
+ (company-update-candidates c)
+ (run-hook-with-args 'company-completion-started-hook
+ (company-explicit-action-p))
+ (company-call-frontends 'show)))))
(cl-return c)))))
(defun company--perform ()
- [elpa] master updated (a2911f6 -> 5deda28), Dmitry Gutov, 2019/04/14
- [elpa] master 4f2d27e 02/31: Avoid using company-preview-frontend when it'll be invisible, Dmitry Gutov, 2019/04/14
- [elpa] master 201577c 01/31: Begin completion on a unique match if the user really wants that,
Dmitry Gutov <=
- [elpa] master efb76d3 06/31: Add a couple of tests for 'unique' behavior, Dmitry Gutov, 2019/04/14
- [elpa] master e5408b5 07/31: Add a clarifying message, Dmitry Gutov, 2019/04/14
- [elpa] master 8576100 08/31: Add a NEWS entry, Dmitry Gutov, 2019/04/14
- [elpa] master 5d3e689 03/31: Update the remaining callers of company-calculate-candidates, Dmitry Gutov, 2019/04/14
- [elpa] master f53327b 12/31: Merge pull request #858 from nikital/tng-fix-lookup-key, Dmitry Gutov, 2019/04/14
- [elpa] master 3873c4a 05/31: Remove outdated comment, Dmitry Gutov, 2019/04/14
- [elpa] master 04b8171 09/31: Fix a typo, Dmitry Gutov, 2019/04/14
- [elpa] master ebf1301 04/31: Merge branch 'master' into forced-completion-for-unique-match, Dmitry Gutov, 2019/04/14
- [elpa] master 3d4e87c 11/31: company: company--company-command-p: Fix lookup-key, Dmitry Gutov, 2019/04/14
- [elpa] master b696b39 10/31: Don't run company-completed-started-hook unnecessarily, Dmitry Gutov, 2019/04/14