Skip to content

Latest commit

 

History

History
263 lines (183 loc) · 8.7 KB

README.org

File metadata and controls

263 lines (183 loc) · 8.7 KB

TabNine

https://melpa.org/packages/tabnine-badge.svg https://github.com/shuxiao9058/tabnine/actions/workflows/melpazoid.yml/badge.svg

An unofficial TabNine(with TabNine Chat supported) package for Emacs.

Screen Recording

TabNine Complete ./assets/screenshot-3.gif

TabNine Chat ./assets/screenshot-4.gif

Screenshot

Snippets displayed with overlay ./assets/screenshot-1.png

Classic completions displayed with capf ./assets/screenshot-2.png

Setup

Installation

Install TabNine package

TabNine is available on Melpa, you can install it with your favorite package manager.

Example for manully install

  • Install tabnine.

Clone or download this repository and add to your load path:

(add-to-list 'load-path "<path-to-tabnine>")
(require 'tabnine)
  • Other configurations, eg: enable tabnine-mode in prog-mode.
(with-eval-after-load 'company
  ;; disable inline previews
  (delq 'company-preview-if-just-one-frontend company-frontends))

(with-eval-after-load 'tabnine
  (define-key tabnine-completion-map (kbd "TAB") #'tabnine-accept-completion)
  (define-key tabnine-completion-map (kbd "<tab>") #'tabnine-accept-completion)

  (define-key tabnine-completion-map (kbd "M-f") #'tabnine-accept-completion-by-word)
  (define-key tabnine-completion-map (kbd "M-<return>") #'tabnine-accept-completion-by-line)

  (define-key tabnine-completion-map (kbd "C-g") #'tabnine-clear-overlay)
  (define-key tabnine-completion-map (kbd "M-[") #'tabnine-next-completion)
  (define-key tabnine-completion-map (kbd "M-]") #'tabnine-previous-completion))

(add-hook 'prog-mode-hook #'tabnine-mode)
(add-hook 'kill-emacs-hook #'tabnine-kill-process)
  • Run M-x tabnine-install-binary to install the TabNine binary for your system.

Example for use-package(straight)

(use-package tabnine
  :commands (tabnine-start-process)
  :hook (prog-mode . tabnine-mode)
  :straight t
  :diminish ""
  :custom
  (tabnine-wait 1)
  (tabnine-minimum-prefix-length 0)
  :hook (kill-emacs . tabnine-kill-process)
  :config
  (add-to-list 'completion-at-point-functions #'tabnine-completion-at-point)
  (tabnine-start-process)
  :bind
  (:map  tabnine-completion-map
	 ("<tab>" . tabnine-accept-completion)
	 ("TAB" . tabnine-accept-completion)
	 ("M-f" . tabnine-accept-completion-by-word)
	 ("M-<return>" . tabnine-accept-completion-by-line)
	 ("C-g" . tabnine-clear-overlay)
	 ("M-[" . tabnine-previous-completion)
	 ("M-]" . tabnine-next-completion)))

Example for Doom Emacs

  • Add package definition to ~/.doom.d/packages.el:
(package! tabnine)
  • Configure tabnine in ~/.doom.d/config.el:
(use-package! tabnine
  :hook ((prog-mode . tabnine-mode)
	 (kill-emacs . tabnine-kill-process))
  :config
  (add-to-list 'completion-at-point-functions #'tabnine-completion-at-point)
  (tabnine-start-process)
  :bind
  (:map  tabnine-completion-map
	("<tab>" . tabnine-accept-completion)
	("TAB" . tabnine-accept-completion)
	("M-f" . tabnine-accept-completion-by-word)
	("M-<return>" . tabnine-accept-completion-by-line)
	("C-g" . tabnine-clear-overlay)
	("M-[" . tabnine-previous-completion)
	("M-]" . tabnine-next-completion)))

Example for Spacemacs

Edit your ~/.spacemacs:

;; ===================
;; dotspacemacs/layers
;; ===================

;; add or uncomment the auto-completion layer
dotspacemacs-configuration-layers
'(
  ...
  auto-completion
  ...
  )

;; add tabnine to additional packages
dotspacemacs-additional-packages
'((tabnine))

;; ========================
;; dotspacemacs/user-config
;; ========================

;; accept completion from tabnine and fallback to company
(with-eval-after-load 'company
  ;; disable inline previews
  (delq 'company-preview-if-just-one-frontend company-frontends))

(with-eval-after-load 'tabnine
  (define-key tabnine-completion-map (kbd "TAB") #'tabnine-accept-completion)
  (define-key tabnine-completion-map (kbd "<tab>") #'tabnine-accept-completion)

  (define-key tabnine-completion-map (kbd "M-f") #'tabnine-accept-completion-by-word)
  (define-key tabnine-completion-map (kbd "M-<return>") #'tabnine-accept-completion-by-line)

  (define-key tabnine-completion-map (kbd "C-g") #'tabnine-clear-overlay)
  (define-key tabnine-completion-map (kbd "M-[") #'tabnine-next-completion)
  (define-key tabnine-completion-map (kbd "M-]") #'tabnine-previous-completion))

(add-hook 'prog-mode-hook 'tabnine-mode)
(add-hook 'kill-emacs-hook #'tabnine-kill-process)

Install TabNine binary

After installed the TabNine package, you should execute tabnine-install-binary interactive command to install Tabnine binary to finish installation.

TabNine configuration

The advanced features(eg: advanced completions, TabNine Chat) requires a TabNine Pro account, open TabNine Hub page with tabnine-configuration after installation. Then login with your account.

TabNine Chat

TabNine Chat is still in BETA - to join the BETA - send Tabnine Pro email to [email protected] to join BETA, while chat fails you can try with vscode to see whether the beta feature is available, also you can view you account’s capabilities with tabnine-capabilities function.

CommandPrompt
tabnine-chat-explain-codeExplain the selected code
tabnine-chat-generate-test-for-codeWrite tests for the selected code
tabnine-chat-document-codeAdd documentation for the selected code
tabnine-chat-fix-codeFind errors in the selected code and fix them

Customization

tabnine-auto-balance

TabNine can automatically balance parentheses, by removing and adding closing parentheses after the cursor. See the examples here.

Default key bindings

tabnine-mode-map

None.

tabnine-completion-map

KeyAction
TABtabnine-accept-completion
C-gtabnine-clear-overlay
M-ftabnine-accept-completion-by-word
M-<return>tabnine-accept-completion-by-line
M-[tabnine-previous-completion
M-]tabnine-next-completion

tabnine-chat-mode-map

KeyAction
C-c RETtabnine-chat-send

Known Issues

Heavily memory and CPU usage

  • TabNine’s local deep learning completion might be enabled by default. It is very CPU-intensive if your device can’t handle it. You can check by typing “TabNine::config” in any buffer (your browser should then automatically open to TabNine’s config page) and disable Deep TabNine Local (you will lose local deep learning completion). More details here.

ICON displayed error

If candidate icons of tabnine displayed unnormally capf icon error, try set kind-icon-mapping for tabnine:

  • With all-the-icons
(add-to-list 'kind-icon-mapping '(tabnine "ai" :icon "cloud" :face shadow) t)
  • With all-the-icons-nerd-fonts
(add-to-list 'kind-icon-mapping `(tabnine ,(nerd-icons-codicon "nf-cod-hubot") :face font-lock-warning-face) t)

Thanks

Thanks to the great work of Tommy Xiang, zerolfx and karthink.

These projects helped me a lot:

https://github.com/TommyX12/company-tabnine

https://github.com/50ways2sayhard/tabnine-capf

https://github.com/zerolfx/copilot.el

https://github.com/karthink/gptel

License

Licensed under GPLv3.