Emacs
Lambdapi source code can be edited with the emacs editor with the major
mode lambdapi-mode
. It requires Emacs 26.1 or higher and provides:
Syntax highlighting for Lambdapi (
*.lp
files) and Dedukti (*.dk
files)Auto indentation for Lambdapi
Easier unicode input
Completion for Lambdapi
Typing of symbol at point (in minibuffer)
Type checking declarations
Short-cuts
C-c C-c
: jump to cursor positionC-c C-n
: next tactic or commandC-c C-p
: previous tactic or commandC-c C-f
: next proofC-c C-b
: previous proofC-c C-e
: toggle electric modeM-;
: (un)comment regionC-x RET C-\
: enter unicode characters in minibuffer using LaTeXM-.
: goto definitionM-x customize-group lambdapi
: customize window layoutC-c C-r
: refresh window layoutC-c C-k
: shutdown LSP serverC-c C-r
: reconnect LSP serverClick on a symbol to discover its type in the bottom line
As always with emacs, if you were to be dissatisfied with these keybindings, you can change them easily!
Installation
The lambdapi-mode
is distributed through MELPA,
so you can use any package manager for Emacs.
Or, provided that MELPA is correctly configured, use the following command inside Emacs:
M-x package-install RET lambdapi-mode RET
where M-x
is usually Alt+x and RET
denotes the Return or Enter key.
Usage
Make sure you have a lambdapi.pkg file in your folder when editing a Lambdapi file in it.
Commenting regions
Lambdapi handles single-line and multi-line comments with //
and
/* ... */
respectively. To comment a region in Emacs, select it and use
M-;
.
Entering unicode
- Company:
if company and company-math are installed, LaTeX commands are autocompleted with the latter tool. Any (or at least a lot of) LaTeX symbol can be entered via its LaTeX command: start typing it, and an autocompletion tooltip should suggest the unicode symbol.
This method is the more complete and easier to use, but depends on
company
.- LambdaPi input method:
if company or company-math is not installed, LaTeX characters can be entered via the LambdaPi input method. Greek characters can be accessed using backquoted letters (as done in cdlatex), or with the LaTeX command: α can be accessed with
`a
or\alpha
, β with`b
or\beta
, and similarly for other Greek letters.
NOTE on the interaction between the input method and company: the
dropdown window of company-math will not appear as long as the current
word is a candidate for a completion of the input method. To favour
company over the input method, the input method can be disabled setting
the variable lambdapi-unicode-prefer-company
to a non-nil value in
~/.emacs
or ~/.emacs.d/init.el
:
(setq lambdapi-unicode-prefer-company 1)
- abbrev mode:
the
abbrev
mode is an emacs minor mode allowing the user to define abbreviations. For instance, one may define “btw” to be an abbreviation of “by the way” with,add-global-abbrev
. Doing so will cause the sequence “btw” to be automatically expanded when the user hitsSPC
orTAB
. The expansion can be inhibited by hittingC-q
beforeSPC
.The function
lambdapi-local-abbrev
can be called when the cursor is at the end of a word to define the word as an abbreviation. When called, the user can input the expanded form in the minibuffer. Additionnally, the abbreviation is added as a directory local variable, so it will be available the next time a file of the project is opened. The functionlambdapi-local-abbrev
is bound toC-c a
.To enter unicode characters in the minibuffer using LaTeX, the TeX input method can be used, for this, once in the minibuffer, enter
C-x RET C-\
and selectTeX
in the list.
LSP server
Electric Terminator mode
You can toggle electric terminators either from the toolbar or
using C-c C-e
. This will evaluate the region till the
cursor whenever you type the ;
terminator or begin
.
Customize window layout
The window layout can be customized in the LambdaPi customization group
(Do M-x customize-group lambdapi
).
The layout can be refreshed with C-c C-r
.
CPU usage and deactivation
If for any reason the LSP server consumes too much power (e.g. if a
non-terminating rewrite system is edited), it can be disabled with
M-x eglot-shutdown
.
Other relevant packages
company: auto-completion
company-math: unicode symbols auto completion
unicode-fonts: to configure correctly Emacs’ unicode fonts
rainbow-delimiters: to appreciate having a lot of parentheses
paredit: to help keeping the parentheses balanced
quickrun: for code evaluation
To have everything configured using use-package, use
(use-package lambdapi-mode
:hook (paredit-mode rainbow-delimiters-mode-enable))