lean4-htt/src/emacs
2016-10-21 15:42:29 -07:00
..
features test(emacs/features): add ecukes template 2014-09-11 12:33:49 -07:00
test feat(emacs): use s-join instead of string-join 2016-01-14 09:36:52 -05:00
.gitignore feat(emacs/Cask): add Cask file 2014-09-09 15:11:57 -07:00
Cask chore(*): cleanup 2016-09-27 17:30:57 -07:00
CMakeLists.txt fix(CMakeLists.txt): quote CMake variables 2015-03-28 22:38:11 -04:00
eri.el feat(emacs/eri.el): add eri.el (from agda mode) 2014-08-30 14:57:34 -07:00
lean-cmd.el feat(emacs/lean-cmd): add SYNC command 2014-10-02 17:30:03 -07:00
lean-company.el chore(emacs/lean-company): disable async auto-completion 2016-10-19 19:47:57 -07:00
lean-debug.el fix(emacs): void-function in lean-debug-mode 2016-10-14 11:53:00 -07:00
lean-flycheck.el refactor(emacs): parse response as plist 2016-10-13 18:49:10 -07:00
lean-info.el feat(emacs): use s-join instead of string-join 2016-01-14 09:36:52 -05:00
lean-input.el chore(emacs/lean-input): add custom shorthands for French quote symbols 2016-10-11 14:17:30 -07:00
lean-mode.el feat(shell/server,emacs/lean-mode): show-goal-at-pos 2016-10-21 15:42:29 -07:00
lean-option.el fix(emacs): set pp.width to column width instead of buffer width of flycheck error list 2016-09-29 15:29:19 -07:00
lean-project.el chore(*): remove legacy flycheck support 2016-10-13 18:49:10 -07:00
lean-require.el chore(*): cleanup 2016-09-27 17:30:57 -07:00
lean-server.el fix(emacs/lean-server): recognize error messages 2016-10-21 15:42:29 -07:00
lean-settings.el feat(emacs): lean-server-restart: interrupt flycheck and bring back keybinding 2016-10-19 10:02:58 -07:00
lean-syntax.el feat(frontends/lean/tactic_notation): allow lemmas to be removed 2016-09-30 19:53:51 -07:00
lean-util.el fix(emacs): don't pass --lean option 2016-09-29 15:29:19 -07:00
lean-variable.el chore(*): cleanup 2016-09-27 17:30:57 -07:00
lean.pgm chore(CMakeLists.txt): move Lean logo to make sure we can test leanemacs without installing Lean 2015-01-31 17:38:49 -08:00
load-lean.el chore(*): cleanup 2016-09-27 17:30:57 -07:00
Makefile fix(emacs/Makefile): add missing Makefile 2014-09-14 23:14:42 -07:00
README.md chore(emacs): update README 2016-09-29 15:29:19 -07:00

Emacs mode for lean theorem prover

Requirements

lean-mode requires Emacs 24 and the following packages, which can be installed via M-x package-install.

The following packages are optional, but we recommend installing them to use full features of lean-mode.

Both the optional and required packages will be installed for you automatically the first time you use lean-mode, if you follow the installation instructions below.

Installation

When Emacs is started, it loads startup information from a special initialization file, often called an "init file." The init file can be found in different places on different systems:

  • Emacs will check for a file named .emacs in your home directory.
  • With GNU Emacs, it is common to use .emacs.d/init.el instead.
  • With Aquamacs, it is common to use ~/Library/Preferences/Aquamacs Emacs/Preferences.el.

On Windows, there are two additional complications:

  • It may be hard to figure out what Emacs considers to be your "home directory".
  • The file explorer may not let you create a file named .emacs, since it begins with a period.

One solution is to run Emacs itself and create the file using C-c C-f (control-C, control-F) and then entering ~/.emacs. (The tilde indicates your home directory.) On Windows, you can also name the file _emacs.

Put the following code in your Emacs init file:

(require 'package)
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/") t)
(when (< emacs-major-version 24)
  ;; For important compatibility libraries like cl-lib
  (add-to-list 'package-archives '("gnu" . "http://elpa.gnu.org/packages/")))
(package-initialize)

;; Install required/optional packages for lean-mode
(defvar lean-mode-required-packages
  '(company dash dash-functional flycheck f
            fill-column-indicator s))
(let ((need-to-refresh t))
  (dolist (p lean-mode-required-packages)
    (when (not (package-installed-p p))
      (when need-to-refresh
        (package-refresh-contents)
        (setq need-to-refresh nil))
      (package-install p))))

Then choose your installation method from the following scenarios, and add the corresponding code to your init file:

Case 1: Build Lean from source

;; Set up lean-root path
(setq lean-rootdir "~/projects/lean")  ;; <=== YOU NEED TO MODIFY THIS
(setq-local lean-emacs-path
            (concat (file-name-as-directory lean-rootdir)
                    (file-name-as-directory "src")
                    "emacs"))
(add-to-list 'load-path (expand-file-name lean-emacs-path))
(require 'lean-mode)

Case 2: Install Lean via apt-get on Ubuntu or via dpkg on Debian

;; Set up lean-root path
(setq lean-rootdir "/usr")
(setq-local lean-emacs-path "/usr/share/emacs/site-lisp/lean")
(add-to-list 'load-path (expand-file-name lean-emacs-path))
(require 'lean-mode)

Case 3: Install Lean via homebrew on OS X

;; Set up lean-root path
(setq lean-rootdir "/usr/local")
(setq-local lean-emacs-path "/usr/local/share/emacs/site-lisp/lean")
(add-to-list 'load-path (expand-file-name lean-emacs-path))
(require 'lean-mode)

Note: if you install homebrew in a custom location that is not the default location, please run brew info lean, and it will tell you where the lean-mode files are located. With that information, update the lean-emacs-path variable accordingly.

Case 4: Install Lean in Windows

;; Set up lean-root path
(setq lean-rootdir "\\lean-0.2.0-windows")
(setq-local lean-emacs-path "\\lean-0.2.0-windows\\share\\emacs\\site-lisp\\lean")
(add-to-list 'load-path (expand-file-name lean-emacs-path))
(require 'lean-mode)

Trying It Out

If things are working correctly, you should see the word Lean in the Emacs mode line when you open a file with extension .lean. If you type

check id

the word check will be underlined, and hovering over it will show you the type of id. The mode line will show FlyC:0/1, indicating that there are no errors and one piece of information displayed. Whenever you type, an asterisk should briefly appear after FlyC, indicating that your file is being checked.

Key Bindings and Commands

Key Function

|M-. | jump to definition in source file (lean-find-tag) |

|TAB | tab complete identifier, option, filename, etc. (lean-tab-indent-or-complete) |

|C-c C-k | shows the keystroke needed to input the symbol under the cursor | |C-c C-g | show goal in tactic proof (lean-show-goal-at-pos) | |C-c C-p | print information about identifier (lean-show-id-keyword-info) |

|C-c C-t | show type (lean-show-type) |

|C-c C-f | replace underscore by inferred value (lean-fill-placeholder) |

|C-c C-x | execute lean in stand-alone mode (lean-std-exe) | |C-c C-l | execute lean in stand-alone mode (lean-std-exe) | |C-c C-o | set option (lean-set-option) | |C-c C-e | evaluate a lean command (lean-eval-cmd) | |C-c C-n | toggle next-error-mode: shows next error in dedicated lean-info buffer | |C-c ! n | flycheck: go to next error | |C-c ! p | flycheck: go to previous error | |C-c ! l | flycheck: show list of errors |

The Flycheck annotation FlyC:n/n indicates the number of errors / responses from Lean. An asterisk *FlyC:n/n indicates that checking is in progress. Clicking on FlyC opens the Flycheck menu.

To profile Lean performace on the file in the buffer, enter M-x lean-execute or choose Lean execute from the Lean menu, and add the option --profile.

Known Issues and Possible Solutions

Unicode

If you experience a problem rendering unicode symbols on emacs, please download the following fonts and install them on your machine:

Then, have the following lines in your emacs setup to use DejaVu Sans Mono font:

(when (member "DejaVu Sans Mono" (font-family-list))
  (set-face-attribute 'default nil :font "DejaVu Sans Mono-11"))

You may also need to install emacs-unicode-fonts package.

  • Run M-x package-refresh-contents, M-x package-install, and type unicode-fonts.

  • Add the following lines in your emacs setup:

(require 'unicode-fonts) (unicode-fonts-setup)


"Variable binding depth exceeds max-specpdl-size" Error
---------------------------------------------------------

See [Issue 906](https://github.com/leanprover/lean/issues/906) for details.
[Moritz Kiefer](https://github.com/cocreature) reported that `proofgeneral`
comes with an old version of `mmm-mode` (0.4.8, released in 2004) on ArchLinux
and it caused this problem. Either removing `proofgeneral` or upgrading
`mmm-mode` to the latest version (0.5.1 as of 2015 Dec) resolves this issue.


Contributions
=============

Contributions are welcome!

If your contribution is a bug fix, create your topic branch from
`master`. If it is a new feature, check if there exists a
WIP(work-in-progress) branch (`vMAJOR.MINOR-wip`). If it does, use
that branch, otherwise use `master`.

Install [Cask](https://github.com/cask/cask) if you haven't already,
then:

 $ cd /path/to/lean/src/emacs
 $ cask

Run all tests with:

 $ make