[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 04/35: Minor tweaks
From: |
Dmitry Gutov |
Subject: |
[elpa] 04/35: Minor tweaks |
Date: |
Sat, 19 Apr 2014 10:12:13 +0000 |
dgutov pushed a commit to branch master
in repository elpa.
commit 3fc9d9ef7b2dd6249b272a25f753dd6ebe412417
Author: Dmitry Gutov <address@hidden>
Date: Wed Mar 26 01:00:40 2014 +0200
Minor tweaks
* Rename --explicit-action to --manual-action.
* Add tests for '("foo" . t), remove some duplicating tests.
* Tweak the defcustom properties.
* Simplify `company--good-prefix-p' a bit more; handle t cdr better.
---
company-tests.el | 21 +++++++++++----------
company.el | 40 ++++++++++++++++++----------------------
2 files changed, 29 insertions(+), 32 deletions(-)
diff --git a/company-tests.el b/company-tests.el
index e5fd2f7..6b7ce88 100644
--- a/company-tests.el
+++ b/company-tests.el
@@ -46,13 +46,15 @@
(ert-deftest company-good-prefix ()
(let ((company-minimum-prefix-length 5)
- company--explicit-action
- (company-selection-changed t)) ;never enough
+ company-abort-manual-when-too-short
+ company--manual-action ;idle begin
+ (company-selection-changed t)) ;has no effect
(should (eq t (company--good-prefix-p "address@hidden")))
(should (eq nil (company--good-prefix-p "abcd")))
(should (eq nil (company--good-prefix-p 'stop)))
(should (eq t (company--good-prefix-p '("foo" . 5))))
- (should (eq nil (company--good-prefix-p '("foo" . 4))))))
+ (should (eq nil (company--good-prefix-p '("foo" . 4))))
+ (should (eq t (company--good-prefix-p '("foo" . t))))))
(ert-deftest company--manual-prefix-set-and-unset ()
(with-temp-buffer
@@ -72,21 +74,20 @@
(ert-deftest company-abort-manual-when-too-short ()
(let ((company-minimum-prefix-length 5)
(company-abort-manual-when-too-short t)
- (company-selection-changed t)) ;never enough
- (let ((company--explicit-action nil)) ;idle begin
+ (company-selection-changed t)) ;has not effect
+ (let ((company--manual-action nil)) ;idle begin
(should (eq t (company--good-prefix-p "address@hidden")))
- (should (eq nil (company--good-prefix-p "abcd")))
- (should (eq nil (company--good-prefix-p 'stop)))
(should (eq t (company--good-prefix-p '("foo" . 5))))
- (should (eq nil (company--good-prefix-p '("foo" . 4)))))
- (let ((company--explicit-action t)
+ (should (eq t (company--good-prefix-p '("foo" . t)))))
+ (let ((company--manual-action t)
(company--manual-prefix "abc")) ;manual begin from this prefix
(should (eq t (company--good-prefix-p "address@hidden")))
(should (eq nil (company--good-prefix-p "ab")))
(should (eq nil (company--good-prefix-p 'stop)))
(should (eq t (company--good-prefix-p '("foo" . 4))))
(should (eq t (company--good-prefix-p "abcd")))
- (should (eq t (company--good-prefix-p "abcd"))))))
+ (should (eq t (company--good-prefix-p "abc")))
+ (should (eq t (company--good-prefix-p '("bar" . t)))))))
(ert-deftest company-multi-backend-with-lambdas ()
(let ((company-backend
diff --git a/company.el b/company.el
index 7f327d4..0ff3e85 100644
--- a/company.el
+++ b/company.el
@@ -449,9 +449,7 @@ back-end, consider using the `post-completion' command
instead."
"If enabled, cancel a manually started completion when the prefix gets
shorter than both `company-minimum-prefix-length' and the length of the
prefix it was started from."
- :group 'company
- :type '(choice (const :tag "Off" nil)
- (const :tag "On" t)))
+ :type 'boolean)
(defcustom company-require-match 'company-explicit-action-p
"If enabled, disallow non-matching input.
@@ -855,9 +853,9 @@ means that `company-mode' is always turned on except in
`message-mode' buffers."
(defvar company-selection-changed nil)
(make-variable-buffer-local 'company-selection-changed)
-(defvar company--explicit-action nil
- "Non-nil, if explicit completion took place.")
-(make-variable-buffer-local 'company--explicit-action)
+(defvar company--manual-action nil
+ "Non-nil, if manual completion took place.")
+(make-variable-buffer-local 'company--manual-action)
(defvar company--manual-prefix nil)
(make-variable-buffer-local 'company--manual-prefix)
@@ -903,7 +901,7 @@ can retrieve meta-data for them."
(defun company-explicit-action-p ()
"Return whether explicit completion action was taken by the user."
- (or company--explicit-action
+ (or company--manual-action
company-selection-changed))
(defun company-reformat (candidate)
@@ -1124,12 +1122,12 @@ Keywords and function definition names are ignored."
(defun company-manual-begin ()
(interactive)
(company-assert-enabled)
- (setq company--explicit-action t)
+ (setq company--manual-action t)
(unwind-protect
(let ((company-minimum-prefix-length 0))
(company-auto-begin))
(unless company-candidates
- (setq company--explicit-action nil))))
+ (setq company--manual-action nil))))
(defun company-other-backend (&optional backward)
(interactive (list current-prefix-arg))
@@ -1199,16 +1197,14 @@ Keywords and function definition names are ignored."
(defun company--good-prefix-p (prefix)
(and (stringp (or (car-safe prefix) prefix)) ;excludes 'stop
- (or (and company--manual-prefix
- ;; changed selection not enough for valid prefix
- (not (and company-abort-manual-when-too-short
- ;; must not be less than minimum or initial length
- (< (or (cdr-safe prefix) (length prefix))
- (min company-minimum-prefix-length
- (length company--manual-prefix))))))
- (or (eq (cdr-safe prefix) t)
- (>= (or (cdr-safe prefix) (length prefix))
- company-minimum-prefix-length)))))
+ (or (eq (cdr-safe prefix) t)
+ (let ((len (or (cdr-safe prefix) (length prefix))))
+ (if company--manual-prefix
+ (or (not company-abort-manual-when-too-short)
+ ;; Must not be less than minimum or initial length.
+ (>= len (min company-minimum-prefix-length
+ (length company--manual-prefix))))
+ (>= len company-minimum-prefix-length))))))
(defun company--continue ()
(when (company-call-backend 'no-cache company-prefix)
@@ -1255,10 +1251,10 @@ Keywords and function definition names are ignored."
c (company-calculate-candidates prefix))
;; t means complete/unique. We don't start, so no hooks.
(if (not (consp c))
- (when company--explicit-action
+ (when company--manual-action
(message "No completion found"))
(setq company-prefix prefix)
- (when company--explicit-action
+ (when company--manual-action
(setq company--manual-prefix prefix))
(when (symbolp backend)
(setq company-lighter (concat " " (symbol-name backend))))
@@ -1309,7 +1305,7 @@ Keywords and function definition names are ignored."
company-common nil
company-selection 0
company-selection-changed nil
- company--explicit-action nil
+ company--manual-action nil
company--manual-prefix nil
company-lighter company-default-lighter
company--point-max nil
- [elpa] branch master updated (0c8e3a1 -> 77719a9), Dmitry Gutov, 2014/04/19
- [elpa] 02/35: More robust and simpler logic in prefix test, Dmitry Gutov, 2014/04/19
- [elpa] 03/35: Test new prefix behavior, option company-abort-manual-when-too-short, Dmitry Gutov, 2014/04/19
- [elpa] 08/35: Use `condition-case-unless-debug', Dmitry Gutov, 2014/04/19
- [elpa] 04/35: Minor tweaks,
Dmitry Gutov <=
- [elpa] 07/35: Drop support for `crop', Dmitry Gutov, 2014/04/19
- [elpa] 10/35: Bump version, Dmitry Gutov, 2014/04/19
- [elpa] 09/35: Add Package-Requires header, Dmitry Gutov, 2014/04/19
- [elpa] 13/35: Make company-clang work asynchronously, Dmitry Gutov, 2014/04/19
- [elpa] 12/35: Remove `company-locate-dominating-file', Dmitry Gutov, 2014/04/19
- [elpa] 16/35: Update NEWS, Dmitry Gutov, 2014/04/19
- [elpa] 17/35: company--merge-async: tweak, Dmitry Gutov, 2014/04/19
- [elpa] 19/35: Move company-elisp require, Dmitry Gutov, 2014/04/19
- [elpa] 14/35: Implement async operation for grouped backends, Dmitry Gutov, 2014/04/19
- [elpa] 18/35: company--force-sync: change calling convention, Dmitry Gutov, 2014/04/19