emacs-elpa-diffs
[Top][All Lists]
Advanced

[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.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]