company-coq

https://github.com/cpitclaudel/company-coq.git

git clone 'git://github.com/cpitclaudel/company-coq.git'
39

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

Completion

Proof-General Extensions

Advanced features

(These require a patched version of coqtop)

Screenshots

Auto-completion of tactics with documentation

Auto-completion of tactics with documentation

Auto-completion of commands with documentation

Auto-completion of commands with documentation

Auto-completion of local definitions

Auto-completion of local definitions

Fuzzy auto-completion of module names

Fuzzy auto-completion of module names

Auto-completion of hypotheses

Auto-completion of hypotheses

Auto-completion of search results

Auto-completion of search results

Keyword beautification

Keyword beautification

Quick help (inline docs)

Quick help (inline docs)

Currently works for symbols and user-defined tactics (prover must be started)

Neat snippets

Insert new match cases Insert new match goal rules

Highlighting of deprecated forms

Highlighting of deprecated forms

Documentation for (documented) error messages

Documentation for (documented) error messages

Outline and folding

Outline Folding

Auto insertion of Proof-General's templates

Auto insertion of Proof-General's templates

Unicode math symbols

Unicode math symbols

Diffs of unification errors

Diffs of unification errors

Auto-completion of theorems and types (w/ patched coqtop, see notes)

Auto-completion of symbol names

(notice the help string in the mini-buffer)

Auto-completion of symbol names with type annotations

Auto-completion of user-defined tactics and tactic notations (w/ patched coqtop)

Auto-completion of user-defined tactics

Auto-completion of user-defined tactic notations

Source view (with patched coqtop)

Source view

Source view on tactics

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. Note that some features, like beautification of symbols or syntax highlighting in the manual, only work with emacs ≥ 24.4.

Proof-General

sudo apt-get install proof-general

(or from source)

company-coq

company-coq is on MELPA. First add the following to your .emacs and restart emacs.

(require 'package)
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/") t)
(package-initialize)

Then type M-x package-refresh-contents RET followed by M-x package-install RET company-coq RET to install and byte-compile company-coq and its dependencies. Some of them 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

You can check out the interactive tutorial by pressing M-x company-coq-tutorial.

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:

Selecting a completion often inserts 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>. Some snippets (like Print Instances) include multiple choices.

Loading company-coq also binds the following keys:

Tips

Troubleshooting

Empty squares in place of math operators, or incorrect line spacing

If you see blank squares appear where there should be math symbols (forall, exists, etc.), or if some lines suddenly become very tall, you may be missing a proper math font. See Installing a math-enabled font, or insert the following snippet in your .emacs to disable symbols beautification:

;; Disable keyword replacement
(setq company-coq-prettify-symbols nil)

Technical note: Proof-General also offers a Unicode keywords facility. company-coq's implementation is based on the prettify-symbols-mode facility found in Emacs 24.4+, yielding a more compact (and faster?) implementation.

Advanced topics

Installing a math-enabled font

For font beautification to work properly, you'll need a font with proper symbol support. DejaVu Sans Mono, Symbola, FreeMono, STIX, Unifont, Segoe UI Symbol, Arial Unicode and Cambria Math do. If Emacs doesn't fallback properly, you can use the following snippet:

(set-fontset-font t 'unicode (font-spec :name "Symbola") nil 'append)

Registering your own symbols and math operators

Adjust and use the following snippet to register your own keywords. This needs be called before (company-coq-initialize), so the code needs to be added after the code listed above.

(add-hook 'coq-mode-hook
          (lambda ()
            (set (make-local-variable 'prettify-symbols-alist)
                 '((":=" . ?≜) ("Proof." . ?∵) ("Qed." . ?■)
                   ("Defined." . ?□) ("Time" . ?⏱) ("Admitted." . ?😱)))))

Greek symbols can be obtained using the following mappings:

'(("Alpha" . ?Α) ("Beta" . ?Β) ("Gamma" . ?Γ)
  ("Delta" . ?Δ) ("Epsilon" . ?Ε) ("Zeta" . ?Ζ)
  ("Eta" . ?Η) ("Theta" . ?Θ) ("Iota" . ?Ι)
  ("Kappa" . ?Κ) ("Lambda" . ?Λ) ("Mu" . ?Μ)
  ("Nu" . ?Ν) ("Xi" . ?Ξ) ("Omicron" . ?Ο)
  ("Pi" . ?Π) ("Rho" . ?Ρ) ("Sigma" . ?Σ)
  ("Tau" . ?Τ) ("Upsilon" . ?Υ) ("Phi" . ?Φ)
  ("Chi" . ?Χ) ("Psi" . ?Ψ) ("Omega" . ?Ω)
  ("alpha" . ?α) ("beta" . ?β) ("gamma" . ?γ)
  ("delta" . ?δ) ("epsilon" . ?ε) ("zeta" . ?ζ)
  ("eta" . ?η) ("theta" . ?θ) ("iota" . ?ι)
  ("kappa" . ?κ) ("lambda" . ?λ) ("mu" . ?μ)
  ("nu" . ?ν) ("xi" . ?ξ) ("omicron" . ?ο)
  ("pi" . ?π) ("rho" . ?ρ) ("sigma" . ?σ)
  ("tau" . ?τ) ("upsilon" . ?υ) ("phi" . ?φ)
  ("chi" . ?χ) ("psi" . ?ψ) ("omega" . ?ω))

in which case you may want to use a custom font for Greek characters:

  (set-fontset-font t 'greek (font-spec :name "DejaVu Sans Mono") nil)

Autocompleting symbols and tactics defined externally

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-dynamic-autocompletion t)

This feature won't work unless you build and use a patched coq REPL: see this fork. One of the relevant patches has been merged upstream; the other two are being discussed here and here.

Disabling some modules

Modules, context, symbols, end of block and search results 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)
(setq company-coq-autocomplete-block-end nil)
(setq company-coq-autocomplete-search-results nil)

You can set these variables using `M-x customize-group RET company-coq RET

Disabling company-coq

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

Installing from source

Dependencies

MELPA

company-coq

mkdir -p ~/.emacs.d/lisp/
git clone https://github.com/cpitclaudel/company-coq.git ~/.emacs.d/lisp/company-coq
cd ~/.emacs.d/lisp/company-coq
make package && make install