[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 4240367 08/78: company-tng: Implement visualisation and co
From: |
Dmitry Gutov |
Subject: |
[elpa] master 4240367 08/78: company-tng: Implement visualisation and completion |
Date: |
Sun, 18 Feb 2018 07:40:11 -0500 (EST) |
branch: master
commit 4240367073ae63a84c473e19de4f5b9e63538c8c
Author: Nikita Leshenko <address@hidden>
Commit: Nikita Leshenko <address@hidden>
company-tng: Implement visualisation and completion
Company Tab and Go inserts the selected candidate as soon as it's selected,
while keeping the completion tooltip open.
---
company-tng.el | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
company.el | 5 ++++
2 files changed, 78 insertions(+)
diff --git a/company-tng.el b/company-tng.el
new file mode 100644
index 0000000..eae4a3a
--- /dev/null
+++ b/company-tng.el
@@ -0,0 +1,73 @@
+;;; company-tng.el --- company-mode frontend that inserts a candidate
+;;; into the buffer as soon as it's selected, Vim style
+
+;; Copyright (C) 2017 Free Software Foundation, Inc.
+
+;; Author: Nikita Leshenko
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
+
+
+;;; Commentary:
+;;
+;; company-tng (tab and go) allows you to use TAB to both select a
+;; completion candidate from the list and to insert it into the
+;; buffer.
+;;
+;; It cycles the candidates like `yank-pop' or `dabbrev-expand' or
+;; Vim: Pressing TAB selects the first item in the completion menu and
+;; inserts it in the buffer. Pressing TAB again selects the second
+;; item and replaces the inserted item with the second one. This can
+;; continue as long as the user wishes to cycle through the menu.
+;;
+;; The benefits are that there is only one shortcut key to interact
+;; with and there is no need to confirm an entry.
+
+;;; Code:
+
+(require 'company)
+(require 'cl-lib)
+
+(defvar-local company-tng--overlay nil)
+
+;;;###autoload
+(defun company-tng-frontend (command)
+ "When the user changes the selection at least once, this
+frontend will display the candidate in the buffer as if it's
+already there and any key outside of `company-active-map' will
+confirm the selection and finish the completion."
+ (cl-case command
+ (show
+ (let ((ov (make-overlay (point) (point))))
+ (setq company-tng--overlay ov)
+ (overlay-put ov 'priority 2)))
+ (update
+ (let ((ov company-tng--overlay)
+ (selected (nth company-selection company-candidates))
+ (prefix (length company-prefix)))
+ (move-overlay ov (- (point) prefix) (point))
+ (overlay-put ov 'display (and company-selection-changed selected))))
+ (hide
+ (when company-tng--overlay
+ (delete-overlay company-tng--overlay)))
+ (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)))))
+
+(provide 'company-tng)
+;;; company-tng.el ends here
diff --git a/company.el b/company.el
index 9c9fb13..ad35411 100644
--- a/company.el
+++ b/company.el
@@ -815,6 +815,11 @@ means that `company-mode' is always turned on except in
`message-mode' buffers."
(defun company-uninstall-map ()
(setf (cdar company-emulation-alist) nil))
+(defun company--company-command-p (keys)
+ "Checks if the keys are part of company's overriding keymap"
+ (or (equal [company-dummy-event] keys)
+ (lookup-key company-my-keymap keys)))
+
;; Hack:
;; Emacs calculates the active keymaps before reading the event. That means we
;; cannot change the keymap from a timer. So we send a bogus command.
- [elpa] master 191fc01 03/78: Merge pull request #694 from ycz0926/master, (continued)
- [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, 2018/02/18
- [elpa] master 4240367 08/78: company-tng: Implement visualisation and completion,
Dmitry Gutov <=
- [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
- [elpa] master 99fa5a0 30/78: Refine col-row calculation in the presence of line numbering, Dmitry Gutov, 2018/02/18