company-ctags icon indicating copy to clipboard operation
company-ctags copied to clipboard

Fastest Emacs auto-completion using Company and Ctags

  • Fastest auto-completion using Company and Ctags [[https://github.com/redguardtoo/company-ctags/actions/workflows/test.yml][https://github.com/redguardtoo/company-ctags/actions/workflows/test.yml/badge.svg]] [[http://melpa.org/#/company-ctags][file:http://melpa.org/packages/company-ctags-badge.svg]] [[http://stable.melpa.org/#/company-ctags][file:http://stable.melpa.org/packages/company-ctags-badge.svg]]

This program enables the completion using [[http://company-mode.github.io][Company mode]] and [[https://en.wikipedia.org/wiki/Ctags][Ctags]] for Emacs. It's fast because a new algorithm is used.

It shows the candidate immediately for huge project like Linux kernel.

[[screenshot.png]]

  • Install and Setup You could place =company-ctags.el= under [[https://www.emacswiki.org/emacs/LoadPath][Load Path]], then add =(require 'company-ctags)= to your configuration.

But I recommend to use [[http://melpa.org/]] to install the package.

Setup is simple, #+BEGIN_SRC emacs-lisp (with-eval-after-load 'company (company-ctags-auto-setup)) #+END_SRC

  • Usage Step 0, Make sure [[http://company-mode.github.io/][company-mode is already set up]].

Step 1, create tags file in project root , #+begin_src sh ctags -e -R . #+end_src

Please note "-e" in ctags cli is not required because both Emacs and Vim tags file are supported since v0.1.0, so below cli is also fine, #+begin_src sh ctags -R . #+end_src

Step 2, enjoy!

  • Tips ** Load extra tags files You can set =company-ctags-extra-tags-files= to load extra tags files,

#+begin_src elisp (setq company-ctags-extra-tags-files '("$HOME/TAGS" "/usr/include/TAGS")) #+end_src

** Ignore case Set =company-ctags-ignore-case= to ignore case when fetching candidates. ** Use CLI program diff to improve performance Make sure CLI program =diff= is executable on Windows.

It's optional but highly recommended. It can speed up tags file updating.

This package uses diff through variable =diff-command=.

Linux/macOS needs no setup. ** Fuzzy match Set =company-ctags-fuzzy-match-p= to fuzzy match the candidates.

The input could match any part of the candidate instead of the beginning of the candidate.

Here is example how to combine [[https://github.com/abo-abo/swiper/blob/master/counsel.el][counsel]] with =company-ctags=, #+begin_src elisp (require 'counsel) (defun my-counsel-company () "Input code from company backend using fuzzy matching." (interactive) (company-abort) (let* ((company-backends '(company-ctags)) (company-ctags-fuzzy-match-p t)) (counsel-company))) #+end_src

You can use [[https://github.com/noctuid/general.el][general.el]] so you could press =rr= in insert mode to trigger =my-counsel-company=, #+begin_src elisp ;; In insert mode, press "rr" in 0.2 second to trigger my-counsel-company (require 'general) (general-imap "r" (general-key-dispatch 'self-insert-command :timeout 0.2 "r" 'my-counsel-company)) #+end_src ** Rust programming language Use [[https://github.com/dan-t/rusty-tags][rusty-tags]] to generate tags file for Rust programming language.

Add below code into ~/.emacs, #+begin_src elisp (setq company-ctags-tags-file-name "rusty-tags.emacs") #+end_src

  • Contact me Report bugs at [[https://github.com/redguardtoo/company-ctags]].
  • License This program is free software: you can redistribute it and/or modify it under the terms of the [[file:LICENSE][GNU General Public License]] as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program 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 [[file:LICENSE][GNU General Public License]] for more details.