[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 74d85d1 09/78: company-tng: Advice company-select-next to
From: |
Dmitry Gutov |
Subject: |
[elpa] master 74d85d1 09/78: company-tng: Advice company-select-next to allow unselected state |
Date: |
Sun, 18 Feb 2018 07:40:12 -0500 (EST) |
branch: master
commit 74d85d15431313913a534dad31344e8fc7e00743
Author: Nikita Leshenko <address@hidden>
Commit: Nikita Leshenko <address@hidden>
company-tng: Advice company-select-next to allow unselected state
company-tng needs an "unselected" state to function intuitively and we
indicate
this state by setting `company-selection-changed' to nil. This advice
allows to
enter and leave unselected state when company-tng is active.
This is an advice and not an internal configuration variable because we
would
like to keep company-tng a separate package for it's unusual semantics.
This is an advice and not a new command because we would like to keep
configuration simple for the users so that they don't have to bind new
commands.
---
company-tng.el | 38 ++++++++++++++++++++++++++++++++++++--
1 file changed, 36 insertions(+), 2 deletions(-)
diff --git a/company-tng.el b/company-tng.el
index eae4a3a..fbb8aa6 100644
--- a/company-tng.el
+++ b/company-tng.el
@@ -53,7 +53,8 @@ confirm the selection and finish the completion."
(show
(let ((ov (make-overlay (point) (point))))
(setq company-tng--overlay ov)
- (overlay-put ov 'priority 2)))
+ (overlay-put ov 'priority 2))
+ (advice-add 'company-select-next :before-until
'company-tng--allow-unselected))
(update
(let ((ov company-tng--overlay)
(selected (nth company-selection company-candidates))
@@ -62,12 +63,45 @@ confirm the selection and finish the completion."
(overlay-put ov 'display (and company-selection-changed selected))))
(hide
(when company-tng--overlay
- (delete-overlay company-tng--overlay)))
+ (delete-overlay company-tng--overlay))
+ (advice-remove 'company-select-next 'company-tng--allow-unselected))
(pre-command
(when (and company-selection-changed
(not (company--company-command-p (this-command-keys))))
(company--unread-this-command-keys)
(setq this-command 'company-complete-selection)))))
+(defun company-tng--allow-unselected (&optional arg)
+ "Advice `company-select-next' to allow for an 'unselected'
+state. Unselected means that no user interaction took place on the
+completion candidates and it's marked by setting
+`company-selection-changed' to nil. This advice will call the underlying
+`company-select-next' unless we need to transition to or from an unselected
+state.
+
+Possible state transitions:
+- (arg > 0) unselected -> first candidate selected
+- (arg < 0) first candidate selected -> unselected
+- (arg < 0 wrap-round) unselected -> last candidate selected
+- (arg < 0 no wrap-round) unselected -> unselected
+
+There is no need to advice `company-select-previous' because it calls
+`company-select-next' internally."
+ (cond
+ ;; Selecting next
+ ((or (not arg) (> arg 0))
+ (unless company-selection-changed
+ (company-set-selection (1- (or arg 1)) 'force-update)
+ t))
+ ;; Selecting previous
+ ((< arg 0)
+ (when (and company-selection-changed
+ (< (+ company-selection arg) 0))
+ (company-set-selection 0)
+ (setq company-selection-changed nil)
+ (company-call-frontends 'update)
+ t)
+ )))
+
(provide 'company-tng)
;;; company-tng.el ends here
- [elpa] master aefac09 05/78: Force the prefix call to synchronous everywhere, (continued)
- [elpa] master aefac09 05/78: Force the prefix call to synchronous everywhere, Dmitry Gutov, 2018/02/18
- [elpa] master 191fc01 03/78: Merge pull request #694 from ycz0926/master, Dmitry Gutov, 2018/02/18
- [elpa] master 5df6abf 12/78: company-tng: Usage instructions, Dmitry Gutov, 2018/02/18
- [elpa] master ec1e879 10/78: company-tng: Don't highlight tooltip when unselected, Dmitry Gutov, 2018/02/18
- [elpa] master 91fc865 07/78: Unread whole command instead of last input, Dmitry Gutov, 2018/02/18
- [elpa] master c0098af 06/78: Introduce company-tooltip-maximum-width, Dmitry Gutov, 2018/02/18
- [elpa] master fe20376 11/78: company-tng: Function to give sensible default configuration, Dmitry Gutov, 2018/02/18
- [elpa] master e27f0f4 13/78: NEWS: Entry for company-tng, Dmitry Gutov, 2018/02/18
- [elpa] master 0295c8f 20/78: And more, Dmitry Gutov, 2018/02/18
- [elpa] master b07eaf9 17/78: Move the entry up, Dmitry Gutov, 2018/02/18
- [elpa] master 74d85d1 09/78: company-tng: Advice company-select-next to allow unselected state,
Dmitry Gutov <=
- [elpa] master 4240367 08/78: company-tng: Implement visualisation and completion, Dmitry Gutov, 2018/02/18
- [elpa] master 1a9f0b8 14/78: company-tng: Kill local overlay variable after completion is done, Dmitry Gutov, 2018/02/18
- [elpa] master a528433 21/78: Fix the link text, Dmitry Gutov, 2018/02/18
- [elpa] master 66a9e65 15/78: company-tng: Use 'after-string when the prefix is empty, Dmitry Gutov, 2018/02/18
- [elpa] master 44b19b6 19/78: Tweak some more, Dmitry Gutov, 2018/02/18
- [elpa] master afa592d 18/78: Rewrite the tng documentation a bit, Dmitry Gutov, 2018/02/18
- [elpa] master eaddef4 22/78: company-tng: Remove redundant call to overlay-put, Dmitry Gutov, 2018/02/18
- [elpa] master 4c1fd0e 16/78: Merge pull request #706 from nikital/company-tng, Dmitry Gutov, 2018/02/18
- [elpa] master 096991d 26/78: Merge pull request #716 from jeffersoncarpenter/master, Dmitry Gutov, 2018/02/18
- [elpa] master 3d9272d 23/78: company-tng: Fully replace default frontend list, Dmitry Gutov, 2018/02/18