/company-coq

Company-mode backend for Proof General's coq-mode

Primary LanguageEmacs LispGNU General Public License v3.0GPL-3.0

company-coq

Company backend for Proof-General's Coq mode. Setup should be pretty straightforward, although the most advanced features require a patched version of coqtop.

Features

  • Auto-completion of math symbols (using company-math)

  • Auto-completion of theorem names defined in the same buffer, with type annotations.

  • Easy access to Proof-General's templates (using yasnippet), with smart templates for sections and modules.

  • Auto-completion of (most of) Coq's tactics and commands, with snippets auto-extracted from the manual.

  • Fuzzy auto-completion of module names in Import commands.

  • Auto-completion of identifiers in proof contexts, and of section and modules names.

  • Documentation for (most) auto-completion entries, with excerpts from the manual shown directly in Emacs.

  • Interactive proof script outline and in-buffer folding

Advanced features (requires a patched version of coqtop):

Screenshots

Autocompletion of tactics with documentation

Autocompletion of tactics with documentation

Autocompletion of commands with documentation

Autocompletion of commands with documentation

Auto insertion of Proof-General's templates

Auto insertion of Proof-General's templates

Fuzzy autocompletion of module names

Fuzzy autocompletion of module names

Auto-completion of identifiers

Auto-completion of identifiers

Outline and folding

Outline

Folding

Unicode math symbols

Unicode math symbols

Autocompletion of symbol names (w/ patched coqtop, see notes)

Autocompletion of symbol names

(notice the help string in the mini-buffer)

Autocompletion of symbol names with type annotations

Setup

Note: You need a version of Emacs >= 24 for this to work properly. You can check which version you are running with M-x emacs-version RET

Coq

sudo apt-get install coq

Proof-General

sudo apt-get install proof-general

(or from source)

company-coq

M-x package-install RET company-coq RET
Note that `company-coq` is on [MELPA](http://melpa.org/#/getting-started). If you don't have it, add the following to your `.emacs` and reload it before running the commands above:
(require 'package)
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/") t)
(package-initialize)

Compiling the dependencies of company-coq will produce a few warnings. That's ok.

Configuration

Add the following to your .emacs

(package-initialize)

;; Open .v files with Proof-General's coq-mode
(require 'proof-site)

;; Load company-coq when opening Coq files
(add-hook 'coq-mode-hook #'company-coq-initialize)

Quick start guide

company-coq should be pretty transparent. Completion windows will pop up when company-coq has suggestions to make. By default, this would be when you start writing a tactic name or a command. You can also launch manual completion by using C-RET (or whatever was originally assigned to proof-script-complete in Coq mode).

Once auto-completion has started, the following key bindings are available:

  • RET selects a completion
  • C-g interrupts completion.
  • C-h and <f1> display documentation for the currently highlighted keyword or identifier.
  • C-M-v scrolls down in the documentation window.
  • C-w opens the relevant section of the documentation, scrolling to the part about the currently highlighted keyword or identifier. Using C-w allows you scroll up (C-M-S-v) in the documentation window to see more context.

You can customize these keybindings by editing company-active-map.

Selecting a completion generally often a snippet with holes at the current point (company-coq uses yasnippet as the snippet backend). You can move between holes by using <tab> and S-<tab>.

Loading company-coq also binds the following keys:

  • C-c C-/ folds the current code block, or all blocs in the file if repeated.
  • C-c C-\ unfolds the current code block, or all blocs in the file if repeated.
  • C-c C-, opens an outline of the code in a separate buffer (using occur).

Advanced topics

Autocompleting symbols

The procedure above will give you auto-completion and documentation for tactics, commands, and theorems that you define locally, but not for theorem names and symbols defined in the libraries you load. To get the latter, add the following to your .emacs, before (company-coq-initialize):

(setq company-coq-autocomplete-symbols-dynamic t)

This feature won't work well unless you build and use a patched coq REPL. This patch should work well for 8.4pl2 and pl3; this one should work on 8.5 and trunk.

Disabling some modules

Modules, context and symbols auto-completion can be turned off using the following lines

(setq company-coq-autocomplete-modules nil)
(setq company-coq-autocomplete-context nil)
(setq company-coq-autocomplete-symbols nil)

Unloading company-coq

M-x unload-feature RET company-coq RET should work fine.

Installing from source

company-coq

mkdir -p ~/.emacs.d/lisp/
git clone https://github.com/cpitclaudel/company-coq.git ~/.emacs.d/lisp/company-coq

Dependencies

M-x package-refresh-contents RET
M-x package-install RET company RET
M-x package-install RET company-math RET
M-x package-install RET yasnippet RET

Configuration

(add-to-list 'load-path "~/.emacs.d/lisp/ProofGeneral/generic/")
(add-to-list 'load-path "~/.emacs.d/lisp/company-coq/")
(require 'company-coq)