Commit 9c3f4e8

agent  ·  2026-10-27 03:27:32 +0000 UTC
parent 4611fb3
emacs: work on a vanilla Emacs (add MELPA if missing, install nael)

lean.el relied on the user's own set-up: MELPA in package-archives and
use-package-always-ensure.  It now needs only Emacs 29.1+ and Lean from
elan.  It still chooses no completion UI: candidates come from eglot
through completion-at-point, so corfu, company or completion-preview-mode
show them.  Tested on a fresh Emacs 31.1 (empty init directory).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,  +26, -10
+3, -3
......@@ -56,18 +56,18 @@ Install the "Lean 4" extension and open the `lean-101` folder. The goal appears
5656
5757 ## Playing in Emacs
5858
59-`emacs/lean.el` sets everything up: [nael](https://codeberg.org/mekeor/nael) (from MELPA) on eglot, a goal window, and indentation that understands Lean. Load it from your `init.el`, after `package-initialize` and with `use-package-always-ensure` (or `:ensure t`):
59+`emacs/lean.el` sets everything up: [nael](https://codeberg.org/mekeor/nael) on eglot, a goal window, and indentation that understands Lean. It needs Emacs 29.1 or later and works on a fresh one: eglot, use-package and ElDoc come with Emacs, and `lean.el` adds MELPA if your Emacs doesn't have it and installs nael from there. Load it from your `init.el`:
6060
6161 ```elisp
6262 (load "/path/to/lean-101/emacs/lean.el")
6363 ```
6464
65-Then open a `.lean` file. Lean starts in the background (the first time takes a few seconds; the mode line shows `[eglot:lean]` when it is ready).
65+The first time, Emacs downloads nael and may show a `*Compile-Log*` buffer with warnings about free variables: they are harmless, close it. Then open a `.lean` file. Lean starts in the background (the first time takes a few seconds; the mode line shows `[eglot:lean]` when it is ready).
6666
6767 - **See the goal:** `C-c C-g` opens the goal window on the right, like the game's right-hand panel. It follows the cursor: at the start of a tactic line it shows the goal before that step, at the end the goal after it. The goal also appears in the echo area as you move.
6868 - **Errors** are underlined. `C-c C-n` jumps to the next one, and its message also shows in the goal window.
6969 - **Symbols:** type `\l` then space for `←`, `\to` for `→`, `\N` for `ℕ`, `\ne` for `≠`. `C-c C-k` lists them all.
70-- **Completion** pops up by itself after 2 characters and a second's pause (or press `C-M-i`). In the popup, TAB and S-TAB move, RET inserts.
70+- **Completion:** `C-M-i` lists the candidates at the cursor. A completion package you already use, such as [corfu](https://github.com/minad/corfu), shows them as you type; on Emacs 30 or later, `M-x completion-preview-mode` shows the best one in grey after the cursor.
7171 - **Indentation:** TAB jumps to the most likely column (2 more after a line ending in `by`, `:=` or `=>`). Press TAB again to cycle through the other sensible columns, and S-TAB to go one level out. RET indents the new line the same way. Lean only accepts spaces, never tab characters, and the setup takes care of that.
7272 - **Check everything:** `C-c C-c` builds the whole project.
7373
+23, -7
......@@ -1,11 +1,26 @@
11 ;;; lean.el --- Emacs set-up for this project (nael + eglot) -*- lexical-binding: t -*-
22
3-;; Load it from your init.el with (load "/path/to/lean-101/emacs/lean.el"),
4-;; after `package-initialize'. See README.md, "In Emacs".
3+;; Load it from your init.el with (load "/path/to/lean-101/emacs/lean.el").
4+;; See README.md, "Playing in Emacs".
55 ;;
6-;; Needs: Emacs 30+ (eglot, use-package), `nael' from MELPA, and
7-;; `use-package-always-ensure' (or add `:ensure t' below). Completion popups
8-;; come from corfu with `corfu-auto' (any completion-at-point UI works).
6+;; Needs: Emacs 29.1+ (eglot, use-package and ElDoc are built in), and Lean
7+;; from elan. It works on a vanilla Emacs: it adds MELPA if it is missing and
8+;; installs `nael' from there. Completion comes from eglot through
9+;; `completion-at-point' (C-M-i), so any completion UI you use shows it (corfu,
10+;; company, `completion-preview-mode', ...); this file doesn't choose one.
11+
12+;; -----------------------------------------------------------------------------
13+;; Packages
14+;; -----------------------------------------------------------------------------
15+;; nael is only on MELPA, which a fresh Emacs doesn't know.
16+(require 'package)
17+(unless (or (assoc "melpa" package-archives)
18+ (seq-some (lambda (a) (string-match-p "melpa\\.org" (cdr a)))
19+ package-archives))
20+ (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t))
21+;; Emacs initializes packages before init.el; this is for an earlier load.
22+(unless (bound-and-true-p package--initialized)
23+ (package-initialize))
924
1025 ;; -----------------------------------------------------------------------------
1126 ;; Lean 4
......@@ -196,8 +211,8 @@ Tab characters in indentation become spaces. Comments are left alone."
196211 (setq-local indent-tabs-mode nil)
197212 (setq-local indent-line-function #'my/lean-indent-line)
198213 (setq-local indent-region-function #'my/lean-indent-region)
199- ;; TAB only indents (and cycles); completion pops up by itself (corfu-auto),
200- ;; or with C-M-i.
214+ ;; TAB indents (and cycles); it doesn't complete. Complete with C-M-i, or
215+ ;; with your completion UI.
201216 (setq-local tab-always-indent t)
202217 ;; RET indents the new line but leaves the one above as typed.
203218 (setq-local electric-indent-inhibit t))
......@@ -207,6 +222,7 @@ Tab characters in indentation become spaces. Comments are left alone."
207222 ;; it through ElDoc. `abbrev-mode' gives the Lean input: \l → ←, \to → →, …
208223 ;; (C-c C-k lists them).
209224 (use-package nael
225+ :ensure t
210226 :hook
211227 (nael-mode . eglot-ensure)
212228 (nael-mode . abbrev-mode)