lean4-htt/lean4-mode
2021-09-21 16:23:52 +02:00
..
.gitignore chore(lean-mode): rename to lean4-mode 2018-09-08 18:37:58 -07:00
lean4-debug.el chore(lean4-mode): rename files 2018-09-08 18:37:58 -07:00
lean4-dev.el chore: restore old lean4-diff-test-file behavior 2020-12-09 18:05:59 +01:00
lean4-eri.el fix: lean4-mode: more fixes, maybe 2021-03-10 18:34:24 +01:00
lean4-fringe.el chore: lean4-mode: support native elisp compilation 2021-09-21 16:23:52 +02:00
lean4-info.el chore: lean4-mode: support native elisp compilation 2021-09-21 16:23:52 +02:00
lean4-input.el chore: lean4-mode: prefer cdot on \. 2021-06-07 13:16:41 +02:00
lean4-leanpkg.el chore(lean4-mode): rename files 2018-09-08 18:37:58 -07:00
lean4-mode.el fix: add lsp-mode to the lean4-mode dependencies 2021-09-07 16:23:18 +02:00
lean4-settings.el feat: lean4-mode: port fringe indicator from lean-mode 2021-06-05 17:13:24 +02:00
lean4-syntax.el chore: lean4-mode: support native elisp compilation 2021-09-21 16:23:52 +02:00
lean4-util.el chore: lean4-mode: remove obsolete dependency 2021-03-05 18:02:48 +01:00
LICENSE chore(lean-mode): rename to lean4-mode 2018-09-08 18:37:58 -07:00
README.md doc: new way to install lean4-mode 2021-09-07 16:23:18 +02:00

Installation

To use lean4-mode in Emacs, add the following to your init.el:

;; You need to modify the following line
(setq load-path (cons "/path/to/lean4/lean4-mode" load-path))

(setq lean4-mode-required-packages '(dash f flycheck lsp-mode magit-section s))

(require 'package)
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))
(package-initialize)
(let ((need-to-refresh t))
  (dolist (p lean4-mode-required-packages)
    (when (not (package-installed-p p))
      (when need-to-refresh
        (package-refresh-contents)
        (setq need-to-refresh nil))
      (package-install p))))

(require 'lean4-mode)

Alternatively if you are a fan of use-package and straight.el you can use:

(use-package lean4-mode
  :straight (lean4-mode :type git :host github :repo "leanprover/lean4"
             :files ("lean4-mode/lean4*.el"))
  ;; to defer loading the package until required
  :commands (lean4-mode))

If you are working on the lean4 repository already and don't want to have two separate checkouts you can use:

(use-package lean4-mode
  :straight (lean4-mode :local-repo "/path/to/your/lean4"
             :files ("lean4-mode/lean4*.el"))
  ;; to defer loading the package until required
  :commands (lean4-mode))

Trying It Out

If things are working correctly, you should see the word Lean 4 in the Emacs mode line when you open a file with extension .lean. Emacs will ask you to identify the "project" this file belongs to. If you then 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.

Settings

Set these with e.g. M-x customize-variable.

  • lsp-headerline-breadcrumb-enable: show a "breadcrumb bar" of namespaces and sections surrounding the current location (default: off)

Key Bindings and Commands

Key Function
C-c C-k show the keystroke needed to input the symbol under the cursor
C-c C-d recompile & reload imports (lean4-refresh-file-dependencies)
C-c C-x execute Lean in stand-alone mode (lean4-std-exe)
C-c C-i toggle info view showing goals and errors at point (lean4-toggle-info-buffer)
C-c ! n flycheck: go to next error
C-c ! p flycheck: go to previous error

For lsp-mode bindings, see https://emacs-lsp.github.io/lsp-mode/page/keybindings/ (not all capabilities are supported currently).

In the default configuration, the Flycheck annotation FlyC:n/n indicates the number of errors / responses from Lean; clicking on FlyC opens the Flycheck menu.