Giter Club home page Giter Club logo

lean-mode's Introduction

This is the Emacs mode for the Lean 3 theorem prover.

Installation

lean-mode requires GNU Emacs 24.3 or newer. The recommended way to install it is via MELPA. If you have not already configured MELPA, put the following code in your Emacs init file (typically ~/.emacs.d/init.el):

(require 'package) ; You might already have this line
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))
(package-initialize) ; You might already have this line

See also MELPA: Getting Started.

With MELPA configured, you can M-x package-install the packages lean-mode and company-lean. The latter package gives you auto completion and is strongly recommended. There is a third package, helm-lean, which provides a searchable list of declarations on C-c C-d using the Helm interface. helm-lean requires Emacs 24.4 or newer.

For company-lean, you should also bind a key to trigger completion, if you have not already done so:

;; Trigger completion on Shift-Space
(global-set-key (kbd "S-SPC") #'company-complete)

Updating

For updating the Lean MELPA packages, use package-list-packages. See the section "Updating Packages" on MELPA: Getting Started for details.

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.

Key Bindings and Commands

Key Function
M-. jump to definition in source file (lean-find-definition)
M-, jump back to position before M-. (xref-pop-marker-stack)
C-c C-k shows the keystroke needed to input the symbol under the cursor
C-c C-x execute lean in stand-alone mode (lean-std-exe)
C-c SPC run a command on the hole at point (lean-hole)
C-c C-d show a searchable list of definitions (helm-lean-definitions)
C-c C-g toggle showing current tactic proof goal (lean-toggle-show-goal)
C-c C-n toggle showing next error in dedicated buffer (lean-toggle-next-error)
C-c C-b toggle showing output in inline boxes (lean-message-boxes-toggle)
C-c C-r restart the lean server (lean-server-restart)
C-c C-s switch to a different Lean version via elan (lean-server-switch-version)
C-c ! n flycheck: go to next error
C-c ! p flycheck: go to previous error
C-c ! l flycheck: show list of errors

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.

Message Boxes

To view the output of commands such as check and print in boxes in the buffer, enable the feature using C-c C-b. If you then type

#check id

a box appears after the line showing the type of id. Customize lean-message-boxes-enabled-captions to choose categories of boxes. In particular, add "trace output" to the list to see proof states and other traces in the buffer.

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 the emacs-unicode-fonts package, after which you should add the following lines to your emacs setup:

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

Contributions

Contributions are welcome!

Building from Source

When working on lean-mode itself, it is much easier to just require the sources than repeatedly building the MELPA packages:

(add-to-list 'load-path "~/path/to/lean-mode/")
(require 'lean-mode)
(require 'company-lean)
(require 'helm-lean)

Make sure you have the packages' dependencies listed on MELPA installed -- the easiest way to do this may be to just install the official Lean MELPA packages and making sure the require commands above are execute before package-initialize.

lean-mode's People

Contributors

anrddh avatar avigad avatar bandali0 avatar basil-conto avatar cdunham avatar cipher1024 avatar collares avatar david-christiansen avatar erdone avatar fpvandoorn avatar gebner avatar iocta avatar jmbr avatar johoelzl avatar jroesch avatar kha avatar kmill avatar kritixilithos avatar leodemoura avatar robertylewis avatar semorrison avatar soonhokong avatar syohex avatar vierkantor avatar yaeldillies avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lean-mode's Issues

Compiling helm-lean yields docstring error

When installing lean-mode from elpa, I get the following error:

In helm-lean-definitions: helm-lean.el:47:2: Warning: docstring has wrong usage of unescaped single quotes (use \= or different quoting)

This may cause issues while the following is probably minor:

In company-lean--exec: company-lean.el:67:2: Warning: docstring wider than 80 characters

lean server sync: (json-readtable-error 99)

Hey hey, I might be doing something wrong..
Once I open a lean file I get the error on the title

Emacs version:
GNU Emacs 27.1 (build 1, x86_64-w64-mingw32) of 2020-08-21

lean version:
Lean (version 4.0.0-m2, commit 26dda3f63d88, Release)

(maybe I should be using an older version of lean?
sorry, I'm really new to the language)

Incorporate in org mode -- implement ob-lean

Hi, I'm newbie about this proof assistant and at the same time avid emacs user. I want to learn Lean for my control system research. I thought it would be great if you can support org mode so that one can exploit literate programming in Lean.

Thanks for your hard work!!

Porting to emacs 28's newer eldoc versions

Some cool changes have been added to the latest versions of eldoc (available in emacs 28), such as no longer having to manually handle eldoc-echo-area-use-multiline-p (and other settings) in eldoc-documentation-function. It would be worth porting to it for emacs 28 users, whilst retaining existing behaviour for those on emacs versions < 28.0. Particularly, instead of the package truncating the docs with an ellipsis (as seen for docs of tactics like simp), for emacs 28 users the full docs can be returned, leaving it to the user to, for example, choose their echo area size.

I have started working on this, if you think this is a good idea, I'll polish my changes and create a pull request.

Problems with exec-path and lean-rootdir

Hi, when I create a .lean file, Emacs shows me the following message:
"lean scroll hook: (error Lean was not found in the ’exec-path’ and ’lean-rootdir’ is not defined. Please set it via M-x customize-variable RET lean-rootdir RET.)"
Does anyone know how can I fix that? I've tried to change the directory through M-x customize variable RET lean-rootdir RET, but then Emacs shows me the following message and nothing happens:
"custom-variable-mark-to-save: Symbol’s value as variable is void:"
Thanks in advance.

filling block comments produces "unexpected end of comment block" error

I open a new mode Lean buffer and put in contents as follows:

/- xxx xxxx xx.xxxxx xx xxxx xx xxxxxx xxx xxxxxxxxx xxxxxxxxx xxxxx, xxxxx xxxxx xxx xxxx xxxxxxxx xxxxxxxxxxxxx. -/

Then push M-q with the cursor anywhere on that line. I get:

/- xxx xxxx xx.xxxxx xx xxxx xx xxxxxx xxx xxxxxxxxx xxxxxxxxx xxxxx,
/- xxxxx xxxxx xxx xxxx xxxxxxxx xxxxxxxxxxxxx. -/

Flycheck now notices an error, unexpected end of comment block (lean-checker) (details via M-x flycheck-list-errors on the second line).


This behaviour could be improved, though I'm not immediately sure what the programming solution is, the expected output would be

/- xxx xxxx xx.xxxxx xx xxxx xx xxxxxx xxx xxxxxxxxx xxxxxxxxx xxxxx,
   xxxxx xxxxx xxx xxxx xxxxxxxx xxxxxxxxxxxxx. -/

Naming of lean-mode and lean4-mode

lean-mode for Lean version 3 is maintained as part of the leanprover Github organization and available via Melpa. lean4-mode for Lean version 4 is maintained in a separate repository under the leanprover-community organization and is not yet available via Melpa. For users, who are unfamiliar with this situation, this may be confusing.

  1. What do you think about renaming lean-mode to lean3-mode?

  2. What do you think about moving the lean4-mode repository to the repository where lean-mode currently resides? The current lean-mode could then move to leanprover/lean3-mode, for example.

  3. How complicated would it be to merge both repositories so that we have one package which supports both versions of Lean?


Related:

Prevent lean-server from complaining when disabling flycheck

I searched the functions provided by the mode and lean-toggle-flycheck-mode appears to be the intended way to disable flycheck, but whenever I toggle it (either manually or via hook) lean-mode complains about it:

error in lean-server command handler: (user-error Flycheck mode disabled)
Server response was:

What is the proper way to disable flycheck with lean-mode then?

build fails on 5.2.6-arch1-1-ARCH

I am trying to build lean on the above kernel.
Checked out 3.4.2 via git.

Output from cmake is:
-- The CXX compiler identification is GNU 9.1.0
-- The C compiler identification is GNU 9.1.0
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- No build type selected, default to Release
-- Lean library will be installed at /usr/local/lib/lean
-- Found GMP: /usr/include (Required is at least version "5.0.5")
-- Using standard malloc.
-- Found PythonInterp: /usr/bin/python (found version "3.7.4")
-- git commit sha1: cbd2b6686ddb566028f5830490fe55c0b3a9a4cb
-- Configuring done
-- Generating done
-- Build files have been written to: /path/to/lean/build/release

now make runs into problems at around 68%:
Scanning dependencies of target standard_lib
[...]
/path/to/lean/library/init/meta/tactic.lean: parsing at /path/to/lean/library/init/meta/tactic.lean: parsing at line 1263terminate called after throwing an instance of 'lean::exception'
what(): vm check failed: is_composite(o) (possibly due to incorrect axioms, or sorry)
make[2]: *** [CMakeFiles/standard_lib.dir/build.make:57: CMakeFiles/standard_lib] Aborted (core dumped)
make[1]: *** [CMakeFiles/Makefile2:930: CMakeFiles/standard_lib.dir/all] Error 2
make: *** [Makefile:163: all] Error 2

I can't track down the issue. Since the same version is compiling well on 4.12.14 with openSuse, I think "sorry" or incorrect axioms is not the problem. Any Ideas?
Thanks in advance!

Difficulty writing multi-line comments due to autocompletion

When writing a multi-line comment like

/--
 Line 1
 Line 2
 ...
 -/

Suppose the user types in /---/ and places the cursor before the last -. Pressing enter there will result in

/---/
/-[CURSOR]-/

This makes it very cumbersome to write multiline comments. Is there a way to disable this behaviour?

wrong lean version used? -- "Syntax checker lean-checker reported too many errors"

Hi, I created a simple project to test out mathlib. It was working initially but revisiting the test file later, I got an error message:

Warning (flycheck): Syntax checker lean-checker reported too many errors (659) and is disabled.

I found that if I switch to a different version of lean with M-x lean-server-switch-version, the error messages stop appearing, and interactions continue as usual.

I have two Lean versions available: stable and 3.4.1. Is there a better way to get lean-mode to use the correct version of Lean on a per-project basis?

font-size in the mini buffer messages

During classes, I would like to increase the size of the fonts in the minibuffer so students can see the types in the cursor position. Any idea? Using the code below I can increase the size in other situations, like list of buffers, but the lean-mode messages remain unchanged.

(add-hook 'minibuffer-setup-hook 'my-minibuffer-setup)
(defun my-minibuffer-setup ()
        (set (make-local-variable 'face-remapping-alist)
          '((default :height 1.2))))

feature request: Please expose lean-message-boxes-enabledp as defcustom

I'm a new lean-mode user and I find that it is really nice to have lean-message-boxes-enabledp on by default. I first checked customize to see if I could change the default but it is declared with defvar so I was unable to configure it via customize. It's a trivial matter for emacs experts to add the following to their init.el, but I think it would be even better if this option was exposed to customize:

(setq-default lean-message-boxes-enabledp t)

Thank you!

Error loading lean-mode in GNU Emacs 30.0.50

I get the following error,

File mode specification error: (error Invalid escape char syntax: \x not followed by hex digit)

when trying to activate lean-mode on any file in GNU Emacs 30.0.50.

"error: type must be string, but is null"

I get this error:

error: type must be string, but is null [3 times]

it seems like lean insists on sending buffer file names that are null:

16:54:28.640 -- server<= {"seq_num":150,"command":"roi","mode":"visible-lines-and-above","files":[{"file_name":"/Users/rgrinberg/tmp/lean/foo.lean","ranges":[{"begin_line":1,"end_line":15},{"begin_line":1,"end_line":15}]},{"file_name":"/Users/rgrinberg/reps/tmp/lean/pnotp.lean","ranges":null}]}
16:54:28.644 -- server<= {"seq_num":151,"command":"roi","mode":"visible-lines-and-above","files":[{"file_name":"/Users/rgrinberg/tmp/lean/foo.lean","ranges":[{"begin_line":1,"end_line":15},{"begin_line":1,"end_line":15}]},{"file_name":"/Users/rgrinberg/reps/tmp/lean/pnotp.lean","ranges":null}]}
16:54:28.674 -- server<= {"seq_num":152,"command":"roi","mode":"visible-lines-and-above","files":[{"file_name":null,"ranges":[{"begin_line":1,"end_line":6}]},{"file_name":"/Users/rgrinberg/tmp/lean/foo.lean","ranges":[{"begin_line":1,"end_line":15}]},{"file_name":"/Users/rgrinberg/reps/tmp/lean/pnotp.lean","ranges":null}]}
16:54:28.675 -- server<= {"seq_num":153,"command":"sync","file_name":null,"content":""}
16:54:28.675 -- server<= {"seq_num":154,"command":"info","file_name":null,"line":1,"column":0}
16:54:28.694 -- server=> {"response":"ok","seq_num":150}

It's probably not a problem, but it's annoying to see this spam in *messages*.

(json-unknown-keyword fish)

I get an error ending in this message (json-unknown-keyword fish) on most any event: opening a file, scrolling the window, etc. So I have not gotten very far in my Lean adventure. :)

I suspect this has something to do with my shell being fish, but I am having some trouble debugging the issue further. Changing my shell to bash has changed the error to (json-readtable-error). Is there a configuration step I'm missing?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.