[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 10a7750 05/10: Track the current selection better
From: |
Dmitry Gutov |
Subject: |
[elpa] master 10a7750 05/10: Track the current selection better |
Date: |
Mon, 02 Feb 2015 15:23:08 +0000 |
branch: master
commit 10a7750fa7dc527f5f41c08db12e833a4424bcef
Author: Dmitry Gutov <address@hidden>
Commit: Dmitry Gutov <address@hidden>
Track the current selection better
* company-update-candidates: Restore selection even if it's 0. Don't rely on
lexical sorting. Compare annotations. Maybe reset
company-selection-changed.
* company-search-mode, company-search-abort: Save and restore the value of
company-selection-changed.
#292
---
NEWS.md | 1 +
company.el | 27 ++++++++++++++++++---------
2 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/NEWS.md b/NEWS.md
index aa98b51..b65d067 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -2,6 +2,7 @@
## Next
+* Better tracking of the current selection.
* Pressing `<up>` or `<down>` doesn't quit the search mode.
## 2015-01-23 (0.8.9)
diff --git a/company.el b/company.el
index 0352ac9..f7f8613 100644
--- a/company.el
+++ b/company.el
@@ -1061,18 +1061,22 @@ can retrieve meta-data for them."
(defun company-update-candidates (candidates)
(setq company-candidates-length (length candidates))
- (if (> company-selection 0)
+ (if company-selection-changed
;; Try to restore the selection
(let ((selected (nth company-selection company-candidates)))
(setq company-selection 0
company-candidates candidates)
(when selected
- (while (and candidates (string< (pop candidates) selected))
- (cl-incf company-selection))
- (unless candidates
- ;; Make sure selection isn't out of bounds.
- (setq company-selection (min (1- company-candidates-length)
- company-selection)))))
+ (catch 'found
+ (while candidates
+ (let ((candidate (pop candidates)))
+ (when (and (string= candidate selected)
+ (equal (company-call-backend 'annotation candidate)
+ (company-call-backend 'annotation selected)))
+ (throw 'found t)))
+ (cl-incf company-selection))
+ (setq company-selection 0
+ company-selection-changed nil))))
(setq company-selection 0
company-candidates candidates))
;; Calculate common.
@@ -1584,6 +1588,8 @@ from the rest of the back-ends in the group, if any, will
be left at the end."
(defvar-local company--search-old-selection 0)
+(defvar-local company--search-old-changed nil)
+
(defun company--search (text lines)
(let ((quoted (regexp-quote text))
(i 0))
@@ -1664,7 +1670,8 @@ from the rest of the back-ends in the group, if any, will
be left at the end."
(interactive)
(company--search-assert-enabled)
(company-search-mode 0)
- (company-set-selection company--search-old-selection t))
+ (company-set-selection company--search-old-selection t)
+ (setq company-selection-changed company--search-old-changed))
(defun company-search-other-char ()
(interactive)
@@ -1731,13 +1738,15 @@ Don't start this directly, use
`company-search-candidates' or
(if company-search-mode
(if (company-manual-begin)
(progn
- (setq company--search-old-selection company-selection)
+ (setq company--search-old-selection company-selection
+ company--search-old-changed company-selection-changed)
(company-call-frontends 'update)
(company-enable-overriding-keymap company-search-map))
(setq company-search-mode nil))
(kill-local-variable 'company-search-string)
(kill-local-variable 'company-search-filtering)
(kill-local-variable 'company--search-old-selection)
+ (kill-local-variable 'company--search-old-changed)
(when company-backend
(company--search-update-predicate "")
(company-call-frontends 'update))
- [elpa] master updated (089d51a -> c5538df), Dmitry Gutov, 2015/02/02
- [elpa] master a015fb3 09/10: Bump the version, Dmitry Gutov, 2015/02/02
- [elpa] master 08ec4cd 03/10: Add a comment, Dmitry Gutov, 2015/02/02
- [elpa] master bb8aa8b 04/10: company-search-map: Include <up> and <down> bindings, Dmitry Gutov, 2015/02/02
- [elpa] master 1b0dc62 06/10: company-search-map: Add company-complete-number bindings, Dmitry Gutov, 2015/02/02
- [elpa] master 10a7750 05/10: Track the current selection better,
Dmitry Gutov <=
- [elpa] master b2de6ad 02/10: Fix version, Dmitry Gutov, 2015/02/02
- [elpa] master 94f2459 07/10: Use mode-line format in company-lighter, Dmitry Gutov, 2015/02/02
- [elpa] master 6fcbcfa 08/10: Pass company-lighter-base to company--group-lighter explicitly, Dmitry Gutov, 2015/02/02
- [elpa] master 3716acb 01/10: Enable company-search-map in company-search-mode body, Dmitry Gutov, 2015/02/02
- [elpa] master c5538df 10/10: Merge commit 'a015fb350abe50d250e3e7a9c3c762397326977f' from company, Dmitry Gutov, 2015/02/02