~/edict

edict

a terminal editor in Bend whose core is proved

the keys of vim · emacs commands as data · 545 laws · 0 open proofs · version 0.1.0

edict edits text files in a terminal. The editor is one pure state machine. A small IO shell reads the keys, draws the frames and writes the files.

The pure part has laws: claims that are true for all inputs. Each law has a proof, and the Bend checker examines each proof. A motion cannot change your text. A load and a save cannot change your file. The cursor cannot leave the screen.

An extension gets these guarantees too, with no new proof.

1.Start

You need devenv. It gives you the Bend compiler and clang.

git clone https://github.com/hyperprior/edict
cd edict
devenv tasks run edict:install   # check the laws, build, install
edict notes.txt

The task builds config.bend, the default configuration, and puts edict at ~/.local/bin/edict. Give it your configuration to build your own edict:

devenv tasks run edict:install --input config=path/to/config.bend

The tasks are in layers. A profile adds the tools and the tasks for one kind of work. Most people need no profile.

profiletaskwhat it does
edict:checkChecks all the laws with bend PROOF.bend. Do this before each commit.
edict:buildBuilds the native binary bin/edict.
edict:installBuilds edict with your configuration and installs it.
devedict:verdictChecks the laws again with the BendTT kernel, which has a proof in Lean.
devedict:testRuns edict in a pseudo-terminal: the key tests and a memory test.
devedict:benchRuns the benchmark against the newest Neovim and Helix.
siteedict:site:buildBuilds this site from the source.
siteedict:site:deployBuilds this site and puts it on edict.computer.
hubedict:hub:publishPublishes edict to the Bend package hub.
devenv --profile dev tasks run edict:test
devenv --profile site tasks run edict:site:deploy

2.Keys

edict uses the keys of vim. In normal mode a key is a command. In insert mode and in replace mode a key is text. In visual mode the motions select text. You type a command line after : and a search after / or ?.

A command in normal mode has three parts: a count, an operator and a motion. Each part is optional.

keyswhat they do
5j 3w 42GA count and a motion: 5 lines down, 3 words on, line 42.
dw d$ dG d/textAn operator and a motion: delete to that position.
dd cc yy >> <<An operator two times: the current line.
3dd d3w 2d3wCounts multiply: 3 lines, 3 words, 6 words.
ciw di( ya"An operator and a text object: a word, the text in brackets, a string.
v V then d c y > <Select characters or lines, then use an operator.
fx tx ; ,Go to the next x on the line, then again, then back.
/pattern n N * #Search for a pattern, for the next place and for the word at the cursor. The matches get a color. While you type the pattern, the cursor shows the first match.
:%s/old/new/g :2,5dReplace a pattern, or delete, in a range of lines.
Control-v then d c y r I ASelect a block of columns, then use an operator or insert on each line. $ makes the block go to the end of each line.
.Does the last change again, with its register. A change is data, so edict keeps it.
u Control-r UUndo, redo, and give back the line as it was when the cursor came to it.
"ayy "ap "+y "_ddA register with a name, the system clipboard, and the register that keeps nothing.
ma 'a `a ''Set a mark, go to its line, go to its position, go back.
Control-o, Control-iGo to the position before a jump, and forward again.
qa ... q @a 3@a @@Record keys as the macro a, then play it. A macro is the text of the register a: "ap pastes it, and text that you yank into a is a macro.
viwp vrxOn a selection: p puts a register in its place, and r makes each character an x.
gqip gqqPuts the words of the lines on lines of the width of the option tw.
&Does the last :s again on the current line.
Control-n, Control-p (insert mode)Completes the word before the cursor from the words of the buffer. Each press gives the next word.
Control-r a (insert mode)Types the text of the register a. " is the register with no name.
gUiw guu g~wOperators for capitals, small letters and the other case.
Control-a, Control-xAdd to the number at the cursor, or subtract from it.
3ix 3ohello 3p 3nA count for an insert, a paste and a search.
Control-w then s v w h j k l c oWindows: split, split side by side, the next window, the window at the left, below, above, at the right, close, and close all the others.
ZZ ZQWrite the file and stop. Stop and write nothing.

With no file, edict starts with a page that shows its name and its version. :version shows the version too.

The operators are d (delete), c (change), y (yank), > and < (indent), gU gu g~ (case) and gq (format). The text objects are iw aw iW aW, the brackets i( i[ i{ i<, the quotes i" i' i`, the paragraph ip and the tag it (the text between <b> and </b>), each with a too.

Patterns

A search and :s use the patterns of vim, in its "magic" form. The engine is a Bend module, src/re.bend. It has a limit of steps for each match, so a pattern cannot stop the editor.

patternwhat it matches
. * \+ \?One character; zero or more; one or more; zero or one.
^ $ \< \>The start and the end of a line; the start and the end of a word.
[abc] [a-z] [^0-9]One character of a set, or one that is not in the set.
\d \w \s \a \l \uA digit, a word character, a blank, a letter, a small letter, a capital. The capital form (\D) is the opposite.
a\|b \(ab\)One or the other; a group.
a\{3} a\{2,4} a\{2,}A count: 3 times; 2 to 4 times; 2 times or more.
\c \CAnywhere in a pattern: capitals and small letters are the same, or are different. These win over the options ic and scs.
& \1 \rIn a replacement: the match, the first group, a new line.

All the bindings

from base_config in src/ed.bend

modekeyscommand
normalh <left> <bs>left
normall <right> <space>right
normalk <up> <c-p>up
normalj <down> <c-n>down
normal<cr> +next-line
normal-prev-line
normal0 <home>home
normal^ _first
normal$ <end>end
normal|column
normalggfirst-line
normalGline
normalwword
normalbword-back
normaleword-end
normalWbig-word
normalBbig-word-back
normalEbig-word-end
normalffind
normalFfind-back
normalttill
normalTtill-back
normal;find-again
normal,find-reverse
normal%match
normal}paragraph
normal{paragraph-back
normalHscreen-top
normalMscreen-middle
normalLscreen-bottom
normal<pgdn> <c-f>page-down
normal<pgup> <c-b>page-up
normal<c-d>half-down
normal<c-u>half-up
normalztview-top
normalzzcenter
normalzbview-bottom
normal/search
normal?search-back
normalnsearch-next
normalNsearch-prev
normal*search-word
normal#search-word-back
normaliinsert
normalaappend
normalAappend-end
normalIinsert-first
normaloopen-below
normalOopen-above
normalRreplace
normalrreplace-char
normalddelete
normalcchange
normalyyank
normal>shift-right
normal<shift-left
normalx <del>delete-char
normalXdelete-back
normalDkill-line
normalCchange-end
normalssubstitute
normalSchange-line
normalYyank-line
normalJjoin
normal~toggle-case
normalppaste
normalPpaste-before
normal, visual"register
normalmmark
normal, visual`goto-mark
normal, visual'goto-mark-line
normal<c-o>jump-back
normal<tab>jump-forward
normalgvreselect
normalqrecord
normal@play
normalgeword-end-back
normalgEbig-word-end-back
normalgUupper
normalgulower
normalg~swap-case
normal, visual<c-v>visual-block
visualIblock-insert
visualAblock-append
visual:visual-command
visualUvisual-upper
visualuvisual-lower
visual~visual-swap-case
normal<c-a>increment
normal<c-x>decrement
normal&substitute-again
normal<c-~>buffer-alt
normal<c-w>w <c-w><c-w>window-next
normal<c-w>W <c-w>pwindow-prev
normal<c-w>j <c-w><down>window-down
normal<c-w>k <c-w><up>window-up
normal<c-w>l <c-w><right>window-right
normal<c-w>h <c-w><left>window-left
normal<c-w>swindow-split
normal<c-w>vwindow-vsplit
normal<c-w>cwindow-close
normal<c-w>qq
normal<c-w>owindow-only
normal<c-w>nnew
normalUline-undo
visualrreplace-char
visualp Pvisual-paste
visual$ <end>visual-end
insert<c-r>insert-register
after an operatoripinner-paragraph
after an operatorapa-paragraph
normaluundo
normal<c-r>redo
normal.repeat
normalvvisual
normalVvisual-line
normal:command
normalZZexit
normalZQq!
normal<c-g>info
visual<esc>normal
visualvvisual
visualVvisual-line
visualovisual-swap
visuald x <del>visual-delete
visualyvisual-yank
visualc svisual-change
visual>visual-shift-right
visual<visual-shift-left
after an operator, visualiwinner-word
after an operator, visualawa-word
after an operator, visualiWinner-big-word
after an operator, visualaWa-big-word
after an operator, visuali( i) ibinner-paren
after an operator, visuala( a) aba-paren
after an operator, visuali[ i]inner-bracket
after an operator, visuala[ a]a-bracket
after an operator, visuali{ i} iBinner-brace
after an operator, visuala{ a} aBa-brace
after an operator, visuali< i>inner-angle
after an operator, visuala< a>an-angle
after an operator, visuali"inner-quote
after an operator, visuala"a-quote
after an operator, visuali'inner-tick
after an operator, visuala'a-tick
after an operator, visuali`inner-backtick
after an operator, visuala`a-backtick
after an operator, visualitinner-tag
after an operator, visualata-tag
normalgqformat
visualgqvisual-format
insert<c-n>complete-next
insert<c-p>complete-prev
insert<esc>leave-insert
insert<cr>type-newline
insert<bs>type-backspace
insert<del>type-delete
insert<tab>type-tab
insert<c-w>type-word-back
insert<c-u>type-line-back
insert<left>left
insert<right>right
insert<up>up
insert<down>down
insert<home>home
insert<end>end

The command line

linewhat it does
:wWrites the file. It refuses when the file changed on the disk after edict read it.
:w nameWrites the text to the file name. It refuses when a different file has this name.
:w! :w! nameWrites, with no check.
:qStops edict. It refuses when there are changes that are not written.
:q!Stops edict and discards the changes.
:wqWrites the file, then stops edict.
:xWrites the file if it has changes, then stops edict. ZZ does the same.
:e nameOpens the file name. The message shows its size, and [dos] or [noeol] when its line ends are not usual.
:e :e!Reads the file again. :e! discards the changes.
:e other :ls :b 2 :b nameMore than one file: each file has its buffer, with its cursor, its undo history and its marks. :ls shows the buffers. :b goes to a buffer by its number or its name. A buffer can have changes while a different one is on the screen.
:bn :bp :bf :bl :b# Control-^The next buffer, the one before, the first, the last, and the buffer that was on the screen before.
:bd :bd 3 :bd!Deletes a buffer. It refuses when the buffer has changes.
:wa :wqa :qa :qa!Writes all the buffers, writes them and stops, stops, stops with no check. :q refuses while a buffer that is not on the screen has changes.
:sp :vsp :sp name :newA new window above, or at the left. It shows the same buffer, or the file name, or a new empty buffer. Each window has its cursor.
:close :only :qCloses the window, or all the other windows. With more than one window, :q and ZZ close the window. With one window, they stop edict.
:r name :r !datePuts a file, or the output of a command, below the line of the cursor. :0r puts it above the first line, and :5r below line 5.
:!lsRuns a command and shows its output. % is the name of the file.
:2,5!sort :%!fmtA filter: the lines go to the command, and its output takes their place. A command that fails changes no text.
:normal Ax :%norm AxTypes keys of the normal mode. With a range, on each line.
:reg :marks :helpShow the registers, the marks, and a short help. A key takes the text away.
:recoverReads the swap file: the text that edict had when it stopped with no warning.
:42 :$Goes to line 42, or to the last line.
:s/old/new/Replaces the first match in the line. With g at the end, all the matches. With i, capitals and small letters are the same. :s alone and & do the last replace again.
:%s/old/new/gThe same in all the lines. A range is before a command: % (all), 2,5, . (this line), $ (the last line), 'a,'b (marks) and '<,'> (the selection). An address can have an offset: .,.+3, $-2, 'a+1.
:2,5d :2,5y :2,5>Deletes, yanks or indents the lines of a range.
:g/pattern/d :v/pattern/dDeletes each line that has a match, or each line that has none. :g! is :v. A range is correct here too.
:nohTakes the color off the matches until the next search.
:map n K up upBinds the key K in normal mode to two commands.
:map nv K upBinds the key in two modes. The modes are n (normal), i (insert), v (visual) and o (after an operator).
:set rnuSets an option, with the names of vim: nu nonu (line numbers), rnu nornu (relative numbers), ai noai (a new line keeps the indent), sw=4 (the indent step), hls nohls (color on the matches), ic noic (a search makes no difference between capitals and small letters), scs noscs (with ic, a capital in the pattern makes the difference), ws nows (a search goes around the end of the text), et noet (the tab key types spaces), tw=72 (the line width for gq; 0 is 79), is nois (a search shows its first match while you type), so=3 (the number of lines that stay above and below the cursor), ts=8 (the columns of a tab stop), ff=dos ff=unix (the line ends of the file), eol noeol (a line end at the end of the file). The long names are correct too.
:nameDoes the command name.

The command line and the search line have a cursor and a history.

keywhat it does
Left, Right, Home, End, Control-b, Control-eMove the cursor in the line.
Backspace, Delete, Control-w, Control-uDelete a character, the word before the cursor, or all the text before it.
Up, Down, Control-p, Control-nGo through the lines that you typed before. Commands and searches have separate lists.
Control-r aTypes the first line of the register a.
TabCompletes the name of a command, an option after set, or the name of a file. Each press gives the next name.

Colors

edict gives colors to comments, strings, numbers, keywords and type names. The language comes from the end of the file name: Bend, Python, JavaScript and TypeScript, C and C++, Rust, Go, Nix, shell, Lua, JSON, TOML, YAML and Markdown. A file with a different name has no colors.

linewhat it does
:syntax off :syntax onTakes the colors away, and gives them back.
:set ft=pythonSets the language of the buffer. The names are bend python javascript typescript c cpp rust go nix sh lua json toml yaml markdown.

The colors are the eight colors of your terminal, so they follow its theme. A language is a table in src/syn.bend: the texts that start a comment, the quotes, and the lists of words. One lexer reads all the languages. A law proves that the lexer gives back each character of a line in its order (lex_keeps_text): colors cannot change the text that you see.

Files

edict writes the file that it read. A file with no line end at its end gets none. A DOS file keeps its line ends, and the buffer shows no carriage returns. Laws prove these two for all texts. A buffer with no lines is an empty file, as in vim.

The last line end of a file is not an empty line in the buffer. The shell does not read that last byte, so the editor makes no pass on the text to take it away.

While the buffer has changes, edict writes a copy of the text to a swap file (.name.edict-swap) after 200 keys, plus one key for each 1,000 bytes of the file. A write and a normal stop delete it. If edict stops with no warning, the next start tells you, and :recover reads the copy.

Start edict with more than one file, and each file is a buffer: edict a.txt b.txt. The status line shows the number of the buffer when there is more than one.

The commands

Each command has a name. A key binding points to a name, and the command line can do any name.

left right up down home end first column top bottom first-line line next-line prev-line next-char prev-char word word-back word-end word-end-back big-word-end-back big-word big-word-back big-word-end find find-back till till-back find-again find-reverse match paragraph paragraph-back page-down page-up half-down half-up screen-top screen-middle screen-bottom view-top center view-bottom search search-back search-next search-prev search-word search-word-back mark goto-mark goto-mark-line jump-back jump-forward reselect record play normal command insert append append-end insert-first open-below open-above leave-insert replace replace-char delete change yank shift-right shift-left upper format lower swap-case increment decrement substitute-again line-undo insert-register delete-char delete-back kill-line change-end substitute delete-line change-line yank-line join toggle-case paste paste-before register undo redo repeat visual visual-line visual-swap visual-block block-insert block-append visual-delete visual-change visual-yank visual-shift-right visual-shift-left visual-upper visual-format complete-next complete-prev visual-lower visual-swap-case visual-command visual-paste visual-end type-newline type-backspace type-delete type-tab type-word-back type-line-back info w q q! wq wq! x! quit quit! registers reg display di marks recover help h x version exit inner-word a-word inner-big-word a-big-word inner-paren a-paren inner-bracket a-bracket inner-brace a-brace inner-angle an-angle inner-quote a-quote inner-tick a-tick inner-backtick a-backtick inner-paragraph a-paragraph inner-tag a-tag qa qa! qall qall! wa wall wqa wqall xa xall ls buffers files bn bnext bp bprevious bN bf bfirst bl blast b# buffer-alt enew new vnew close clo only on window-split window-vsplit window-close window-only window-next window-prev window-down window-up window-right window-left

3.Extend

edict has no configuration language. Your configuration is a Bend program, and you compile it into your own edict. The checker examines your configuration with the editor. A wrong name or a wrong type stops the build, not your work.

The default configuration is the file config.bend. The install task builds it when you give it no other file:

config.bend

import Base
import ./src/app.bend as Edict
import ./src/cmd.bend as C
import ./src/ed.bend as E

# The default configuration
# =========================
# `devenv tasks run edict:install` builds this file when you give it no
# other configuration.
#
# Use this file as the base of your own configuration: make a copy,
# change it, and give the copy to the task:
#
#   devenv tasks run edict:install --input config=path/to/my.bend
#
# A configuration is a Bend program. The checker examines it with the
# editor, so a wrong name or a wrong type stops the build. The imports
# start at the root of the edict repository. config/example.bend has an
# example of each part.

# The options: the defaults with these changes. Relative line numbers:
# the line of the cursor shows its number, and each other line shows its
# distance to that line. The other options are E.Number{..},
# E.AutoIndent{..}, E.Shift{4n} and E.HlSearch{..}.
def opts() -> E.Opts:
  E.options([E.Relative{True{}}])

# Named actions, for `:name` and for the command lines below. An action
# is a value that you make from motions (C.Move) and edits (C.Edit).
def actions() -> List<&2, E.Named>:
  Nil{}

# Key bindings to actions: E.Bound{modes, keys, action}.
def keys() -> List<&2, E.Bound>:
  Nil{}

# Command lines, such as "map n K page-up".
def lines() -> List<&2, String>:
  Nil{}

def main() -> IO(Unit):
  Edict.run(E.Config{opts(), actions(), keys(), lines()})

Use that file as the base of your own configuration. Make a copy, change it, and give the copy to the install task:

cp config.bend ~/my-edict.bend
devenv tasks run edict:install --input config=~/my-edict.bend

The task puts a file that is not in the repository at its root, so the imports of your file start with ./src/. The result is ~/.local/bin/edict. E.options gives the default options with your changes. Thus your file stays correct when edict gets a new option.

A configuration has four parts.

parttypewhat it is
optsE.OptsThe options: E.Number and E.Relative for the line numbers, E.AutoIndent, E.Shift for the indent step, E.HlSearch, E.IgnoreCase, E.SmartCase, E.WrapScan, E.ExpandTab, E.TextWidth, E.IncSearch, E.ScrollOff, E.TabStop and E.Syntax.
actionsList<E.Named>Actions with a name, for :name and for command lines.
keysList<E.Bound>Key bindings to action values: the modes, the keys, the action.
linesList<String>Command lines, such as map n K page-up.

Two more ways change edict with no new build. They use command lines.

  1. While edict runs. Type :map n Q top or :set rnu. The change is there until edict stops.
  2. The init file. edict reads ~/.config/edict/init at the start, after your configuration. Each line is a command line. A line that starts with # is a comment.

~/.config/edict/init

# my keys
map n K page-up
map n \t top
map i <c-a> home
set rnu

A key name is one character, or a name in angle brackets: <cr> <esc> <bs> <tab> <del> <up> <down> <left> <right> <home> <end> <pgup> <pgdn> <space>, and <c-x> for Control-x. The modes are n (normal), i (insert), v (visual) and o (after an operator). A binding of your own wins over a default binding. The key \ starts no command in vim, so it is a good first key for your commands.

Commands are data

A motion is a value of the type C.Move. An edit is a value of the type C.Edit. You make a new command from these values. The laws are about all values of these types. Thus your command has the same guarantees, and you write no new proof.

The keys of vim are made the same way. dw is the value Op{Delete{}, 0n, Motion{C.Do{C.WordFwd{..}}, Excl{}}}. The key . does that value again.

config/example.bend

import Base
import ../src/app.bend as Edict
import ../src/cmd.bend as C
import ../src/ed.bend as E

# An example configuration
# ========================
# A configuration is a Bend program. Its `main` gives a value of the type
# E.Config to Edict.run. The checker examines your configuration with the
# editor, so a wrong name or a wrong type stops the build.
#
# The task edict:example builds this file. It makes bin/edict-example.

# The options: line numbers, and relative line numbers.
def opts() -> E.Opts:
  E.options([E.Relative{True{}}])

# Named actions. `:name` does one, and a command line can use one.
#
# An action is a value. You make it from motions (C.Move), edits (C.Edit)
# and other actions (E.Act). The laws in LAWS.bend are about ALL these
# values. Thus your commands get the same guarantees with no new proof:
# a motion cannot change the text, and an edit cannot break the buffer.
def actions() -> List<&2, E.Named>:
  [
    E.Named{"duplicate-line", E.Both{E.Op{E.Yank{}, 0n, E.Self{}}, E.Paste{False{}, 0n}}},
    E.Named{"end-word", E.Motion{C.Then{C.Do{C.End{}}, C.Do{C.WordBack{False{}}}}, E.Excl{}}}
  ]

# Key bindings to actions. The action needs no name. The key `\` starts
# no command in vim, so it is free for your commands.
def keys() -> List<&2, E.Bound>:
  [
    E.Bound{"n", "\\*", E.Edit{C.Seq{C.Go{C.Do{C.Home{}}}, C.Seq{C.Ins{'*'}, C.Ins{' '}}}}},
    E.Bound{"nv", "\\j", E.Motion{C.Times{5n, C.Do{C.Down{}}}, E.Rows{}}}
  ]

# Command lines, the same as in the file ~/.config/edict/init.
def lines() -> List<&2, String>:
  [
    "map n \\d duplicate-line",
    "map n \\e end-word"
  ]

def main() -> IO(Unit):
  Edict.run(E.Config{opts(), actions(), keys(), lines()})

The task edict:example compiles that file into bin/edict-example. It adds these commands and these bindings:

duplicate-line end-word

modekeyscommand
normal\*an action value
normal, visual\jan action value
normal\dduplicate-line
normal\eend-word

The command end-word is a motion. The law move_text is about all motions. So end-word cannot change the text. The key \* is an edit, and the law edit_ok is about all edits. So it cannot break the buffer.

4.Laws

LAWS.bend has 545 laws. PROOF.bend has a proof for each law, and the lemmas that the proofs use.

$ bend PROOF.bend
ALL PROOFS CHECK
$ bend PROOF.bend --verdict   # the kernel with a proof in Lean
ALL PROOFS CHECK

The laws use a model of the buffer. B.before(b) is the text before the cursor, in reverse. B.after(b) is the text after the cursor. B.text(b) is all the text.

The text below comes from LAWS.bend when the site is built. Thus this page and the code agree.

The largest guarantee is a type

A buffer has a small cache: the number of the cursor line. A wrong cache breaks the screen and the line numbers. B.ok(b) says that the cache of b is correct.

type Good is Data:
  Good{b: B.Buf, -ok: B.ok(b)}     # a buffer WITH the proof that it is correct

The history of the editor holds Good values only. So the editor has no way to keep a buffer that has no proof. When a change to the code can break a buffer, the editor does not compile. This is true for each action, each key, each macro and each extension, and no one writes a proof for each of them. The proof field is erased: it costs no time and no memory when edict runs. The laws state_ok, action_ok and key_ok in section 4.15 say it: after each action and each key, the buffer is correct.

4.1Edits change the text only at the cursor

law insert_before:
  for b: B.Buf
  for c: Char
  {B.before(B.insert(b, c)) == SCon{c, B.before(b)} : String}

law insert_after:
  for b: B.Buf
  for c: Char
  {B.after(B.insert(b, c)) == B.after(b) : String}

law newline_before:
  for b: B.Buf
  {B.before(B.newline(b)) == SCon{'\n', B.before(b)} : String}

law newline_after:
  for b: B.Buf
  {B.after(B.newline(b)) == B.after(b) : String}

law backspace_before:
  for b: B.Buf
  {B.before(B.backspace(b)) == B.tail(B.before(b)) : String}

law backspace_after:
  for b: B.Buf
  {B.after(B.backspace(b)) == B.after(b) : String}

law delete_before:
  for b: B.Buf
  {B.before(B.delete(b)) == B.before(b) : String}

law delete_after:
  for b: B.Buf
  {B.after(B.delete(b)) == B.tail(B.after(b)) : String}

4.2Backspace is the inverse of an insertion

law backspace_insert:
  for b: B.Buf
  for c: Char
  {B.backspace(B.insert(b, c)) == b : B.Buf}

law backspace_newline:
  for b: B.Buf
  {B.backspace(B.newline(b)) == b : B.Buf}

4.3A motion does not change the text

law left_text:
  for b: B.Buf
  {B.text(B.left(b)) == B.text(b) : String}

law right_text:
  for b: B.Buf
  {B.text(B.right(b)) == B.text(b) : String}

law home_text:
  for b: B.Buf
  {B.text(B.home(b)) == B.text(b) : String}

law end_text:
  for b: B.Buf
  {B.text(B.end(b)) == B.text(b) : String}

law up_text:
  for b: B.Buf
  {B.text(B.up(b)) == B.text(b) : String}

law down_text:
  for b: B.Buf
  {B.text(B.down(b)) == B.text(b) : String}

law next_text:
  for b: B.Buf
  {B.text(B.next(b)) == B.text(b) : String}

law prev_text:
  for b: B.Buf
  {B.text(B.prev(b)) == B.text(b) : String}

law clamp_text:
  for +b: B.Buf
  {B.text(B.clamp(b)) == B.text(b) : String}

law top_text:
  for b: B.Buf
  {B.text(B.top(b)) == B.text(b) : String}

law bottom_text:
  for b: B.Buf
  {B.text(B.bottom(b)) == B.text(b) : String}

4.4A file is not changed by a load and a save

law load_before:
  for s: String
  {B.before(B.load(s)) == "" : String}

law load_after:
  for s: String
  {B.after(B.load(s)) == s : String}

law load_text:
  for +s: String
  {B.text(B.load(s)) == s : String}

4.5Motions are data, and NO motion can change the text

These laws are about every value of the types C.Prim and C.Move. A key binding or an extension that is made from motions gets this guarantee. The word motions, `f` and `t`, `%`, the paragraph motions and the jump of a search are values of C.Prim. Thus the laws are about them too.

law prim_text:
  for p: C.Prim
  for +b: B.Buf
  {B.text(C.prim(p, b)) == B.text(b) : String}

law move_text:
  for +m: C.Move
  for k: Nat
  for +b: B.Buf
  {B.text(C.move(m, k, b)) == B.text(b) : String}

law motion_keeps_text:
  for +m: C.Move
  for k: E.Span
  for e: E.Ed
  {B.text(E.buf(E.run(E.Motion{m, k}, e))) == B.text(E.buf(e)) : String}

4.6The row cache is always correct

B.ok(b) says that the row number in b is the number of lines above the cursor. A load makes it true. NO edit and NO motion can make it false.

law load_ok:
  for s: String
  B.ok(B.load(s))

law move_ok:
  for +m: C.Move
  for k: Nat
  for +b: B.Buf
  for ok: B.ok(b)
  B.ok(C.move(m, k, b))

law edit_ok:
  for +e: C.Edit
  for k: Nat
  for +b: B.Buf
  for ok: B.ok(b)
  B.ok(C.edit(e, k, b))

law cut_ok:
  for k: Nat
  for +b: B.Buf
  for ok: B.ok(b)
  B.ok(B.cut(k, b))

law recase_ok:
  for +d: Nat
  for +f: Nat
  for +b: B.Buf
  for ok: B.ok(b)
  B.ok(B.recase(d, f, b))

law subst_ok:
  for n: Nat
  for +p: R.Pat
  for +rp: List<&2, R.RTok>
  for +all: Bool
  for +b: B.Buf
  for ok: B.ok(b)
  B.ok(B.subst(n, p, rp, all, b))

law subst_miss:
  for p: R.Pat
  for rp: List<&2, R.RTok>
  for all: Bool
  for b: B.Buf
  {B.subst.if(False{}, p, rp, all, b) == b : B.Buf}

law subst_zero:
  for p: R.Pat
  for rp: List<&2, R.RTok>
  for all: Bool
  for b: B.Buf
  {B.subst(0n, p, rp, all, b) == b : B.Buf}

4.7An undo gives back the buffer, and a redo gives back the edit

law undo_edit:
  for h: H.Hist
  for b: S.Good
  {H.now(H.undo(H.set(H.commit(h), b))) == H.now(h) : S.Good}

law redo_undo:
  for h: H.Hist
  for b: S.Good
  {H.redo(H.undo(H.set(H.commit(h), b))) == H.set(H.commit(h), b) : H.Hist}

4.8The cursor is always on the screen

W.scroll gives the first line of a window of 1n+k lines. The position pos is not above the window, and it is not below the window.

law scroll_low:
  for +top: Nat
  for +pos: Nat
  for +k: Nat
  {Nat.is_le(W.scroll(top, pos, 1n+k), pos) == True{} : Bool}

law scroll_high:
  for +top: Nat
  for +pos: Nat
  for +k: Nat
  {Nat.is_le(Nat.sub(pos, W.scroll(top, pos, 1n+k)), k) == True{} : Bool}

4.9An operator deletes the text that it copies, and no other text

`d` and `c` delete k characters after the cursor with B.cut. `y` copies them with B.grab. `p` puts text at the cursor with B.paste. A delete does not change the text before the cursor.

law cut_before:
  for k: Nat
  for +b: B.Buf
  {B.before(B.cut(k, b)) == B.before(b) : String}

law cut_grab:
  for k: Nat
  for b: B.Buf
  {String.append(B.grab(k, b), B.after(B.cut(k, b))) == B.after(b) : String}

law paste_before:
  for s: String
  for +b: B.Buf
  {B.before(B.paste(s, b)) == String.reverse.go(s, B.before(b)) : String}

law paste_after:
  for s: String
  for +b: B.Buf
  {B.after(B.paste(s, b)) == B.after(b) : String}

law paste_cut:
  for +k: Nat
  for +b: B.Buf
  {B.text(B.paste(B.grab(k, b), B.cut(k, b))) == B.text(b) : String}

4.10A relative line number is the distance to the line of the cursor

W.gap(a, b) is the number that the line a shows when the cursor is on the line b. The line of the cursor is at the distance 0.

law gap_self:
  for a: Nat
  {W.gap(a, a) == 0n : Nat}

law gap_sym:
  for a: Nat
  for b: Nat
  {W.gap(a, b) == W.gap(b, a) : Nat}

law gap_step:
  for a: Nat
  for b: Nat
  {W.gap(1n+a, 1n+b) == W.gap(a, b) : Nat}

4.11More about edits and motions

These laws keep the small rules of the buffer the same when the code changes. An edit on the current line does not change the text before the cursor.

law kill_before:
  for b: B.Buf
  {B.before(B.kill(b)) == B.before(b) : String}

law swap_before:
  for b: B.Buf
  for c: Char
  {B.before(B.swap(b, c)) == B.before(b) : String}

law cut1_before:
  for b: B.Buf
  {B.before(B.cut1(b)) == B.before(b) : String}

law swap_rest:
  for b: B.Buf
  for c: Char
  {B.tail(B.after(B.swap(b, c))) == B.tail(B.after(b)) : String}

law flip_after:
  for b: B.Buf
  {B.after(B.flip(b)) == B.after(B.right(b)) : String}

law flip_before:
  for b: B.Buf
  {B.tail(B.before(B.flip(b))) == B.tail(B.before(B.right(b))) : String}

law case1_after:
  for f: Nat
  for b: B.Buf
  {B.after(B.case1(f, b)) == B.after(B.right(b)) : String}

law bs_home_after:
  for b: B.Buf
  {B.after(B.bs_home(b)) == B.after(b) : String}

law bs_word_after:
  for b: B.Buf
  {B.after(B.bs_word(b)) == B.after(b) : String}

law home_home:
  for b: B.Buf
  {B.home(B.home(b)) == B.home(b) : B.Buf}

law end_end:
  for b: B.Buf
  {B.end(B.end(b)) == B.end(b) : B.Buf}

law home_col:
  for b: B.Buf
  {B.col(B.home(b)) == 0n : Nat}

law top_row:
  for b: B.Buf
  {B.row(B.top(b)) == 0n : Nat}

law clamp_clamp:
  for b: B.Buf
  {B.clamp(B.clamp(b)) == B.clamp(b) : B.Buf}

law text_at_short:
  for col: Nat
  for s: String
  for b: B.Buf
  {B.text_at.if(False{}, False{}, col, s, b) == b : B.Buf}

4.12Undo, and actions that are not edits

An undo after an edit action gives back the buffer.

law undo_action:
  for +x: C.Edit
  for e: E.Ed
  {E.buf(E.run(E.Undo{}, E.run(E.Edit{x}, e))) == E.buf(e) : B.Buf}

law redo_action:
  for +x: C.Edit
  for e: E.Ed
  {E.buf(E.run(E.Redo{}, E.run(E.Undo{}, E.run(E.Edit{x}, e)))) == E.buf(E.run(E.Edit{x}, e)) : B.Buf}

law motion_no_step:
  for +m: C.Move
  for k: E.Span
  for e: E.Ed
  {H.past(E.hist(E.run(E.Motion{m, k}, e))) == H.past(E.hist(e)) : List<&2, S.Good>}

law typed_no_step:
  for +x: C.Edit
  for e: E.Ed
  {H.past(E.hist(E.run(E.Typed{x}, e))) == H.past(E.hist(e)) : List<&2, S.Good>}

law msg_keeps_buf:
  for s: String
  for e: E.Ed
  {E.buf(E.run(E.Msg{s}, e)) == E.buf(e) : B.Buf}

law mode_keeps_buf:
  for m: E.Mode
  for e: E.Ed
  {E.buf(E.run(E.SetMode{m}, e)) == E.buf(e) : B.Buf}

law option_keeps_buf:
  for o: E.Opt
  for e: E.Ed
  {E.buf(E.run(E.Option{o}, e)) == E.buf(e) : B.Buf}

law noh_keeps_buf:
  for e: E.Ed
  {E.buf(E.run(E.NoHl{}, e)) == E.buf(e) : B.Buf}

law bind_keeps_buf:
  for key: String
  for a: E.Act
  for e: E.Ed
  {E.buf(E.run(E.Bind{key, a}, e)) == E.buf(e) : B.Buf}

4.13Registers and counts

The register `_` keeps nothing: the unnamed register stays.

law hole_keeps_reg:
  for e: E.Ed
  for text: String
  for lines: Bool
  for yank: Bool
  {E.reg(E.store.in(e, text, lines, False{}, yank, 1n)) == E.reg(e) : String}

law store_unnamed:
  for e: E.Ed
  for +text: String
  for lines: Bool
  for yank: Bool
  {E.reg(E.store.in(e, text, lines, False{}, yank, 0n)) == text : String}

law total_left:
  for n: Nat
  {E.total(0n, n) == n : Nat}

law total_right:
  for n: Nat
  {E.total(n, 0n) == n : Nat}

law times_motion:
  for m: C.Move
  for k: E.Span
  {E.times(E.Motion{m, k}, 0n) == E.Motion{m, k} : E.Act}

law times_edit:
  for x: C.Edit
  {E.times(E.Edit{x}, 0n) == E.Edit{x} : E.Act}

4.14The pattern machine

The machine always stops: with no fuel there is no match.

law run_stops:
  for ok: Bool
  for k: List<&2, R.Re>
  for s: String
  for pos: Nat
  for prev: Char
  for caps: List<&2, R.Cap>
  for stack: List<&2, R.Frame>
  {R.run(0n, ok, k, s, pos, prev, caps, stack) == R.no() : R.Res}

law run_done:
  for f: Nat
  for s: String
  for pos: Nat
  for prev: Char
  for caps: List<&2, R.Cap>
  for stack: List<&2, R.Frame>
  {R.run(1n+f, True{}, Nil{}, s, pos, prev, caps, stack) == R.Res{True{}, pos, caps} : R.Res}

law run_fail:
  for f: Nat
  for k: List<&2, R.Re>
  for s: String
  for pos: Nat
  for prev: Char
  for caps: List<&2, R.Cap>
  {R.run(1n+f, False{}, k, s, pos, prev, caps, Nil{}) == R.no() : R.Res}

law expand_nil:
  for m: String
  for caps: List<&2, R.Cap>
  {R.expand(Nil{}, m, caps) == "" : String}

4.15NO action and NO key can break the buffer

B.ok(b) says that the row cache of the buffer b is correct. These laws are about ALL actions and ALL keys: operators, registers, macros, `:s`, and each action that an extension makes. The proof comes from a type. S.Good (src/safe.bend) is a buffer WITH the proof of B.ok. The history of the editor holds S.Good values only, and the editor has no other way to keep a buffer. Thus the checker refuses the editor itself when a change to the code can break a buffer. The proof in a S.Good is erased: it costs nothing when edict runs. S.Holds<P> says that the claim P has a proof. The buffer of each state is correct.

law state_ok:
  for e: E.Ed
  S.Holds<B.ok(E.buf(e))>

law action_ok:
  for a: E.Act
  for e: E.Ed
  S.Holds<B.ok(E.buf(E.run(a, e)))>

law key_ok:
  for e: E.Ed
  for k: K.Key
  S.Holds<B.ok(E.buf(E.key(e, k)))>

law history_ok:
  for g: S.Good
  S.Holds<B.ok(S.buf(g))>

law safe_move:
  for m: C.Move
  for g: S.Good
  {S.buf(S.move(m, g)) == C.move(m, 1n, S.buf(g)) : B.Buf}

law safe_edit:
  for x: C.Edit
  for g: S.Good
  {S.buf(S.edit(x, g)) == C.edit(x, 1n, S.buf(g)) : B.Buf}

law safe_cut:
  for d: Nat
  for g: S.Good
  {S.buf(S.cut(d, g)) == B.cut(d, S.buf(g)) : B.Buf}

law safe_recase:
  for d: Nat
  for f: Nat
  for g: S.Good
  {S.buf(S.recase(d, f, g)) == B.recase(d, f, S.buf(g)) : B.Buf}

law safe_subst:
  for n: Nat
  for p: R.Pat
  for rp: List<&2, R.RTok>
  for all: Bool
  for g: S.Good
  {S.buf(S.subst(n, p, rp, all, g)) == B.subst(n, p, rp, all, S.buf(g)) : B.Buf}

law safe_jump:
  for u: Nat
  for d: Nat
  for c: Nat
  for g: S.Good
  {S.buf(S.jump(u, d, c, g)) == B.jump(u, d, c, S.buf(g)) : B.Buf}

law safe_clamp:
  for g: S.Good
  {S.buf(S.clamp(g)) == B.clamp(S.buf(g)) : B.Buf}

law safe_load:
  for s: String
  {S.buf(S.load(s)) == B.load(s) : B.Buf}

law state_buf:
  for e: E.Ed
  {E.buf(e) == S.buf(H.now(E.hist(e))) : B.Buf}

4.16Options

An option that you set has the value that you gave. An option that you did not set has its value from before.

law options_nil:
  {E.options(Nil{}) == E.defaults() : E.Opts}

law opt_set_number:
  for o: E.Opts
  for v: Bool
  {E.opt.number(E.opts.set(o, E.Number{v})) == v : Bool}

law opt_set_relative:
  for o: E.Opts
  for v: Bool
  {E.opt.relative(E.opts.set(o, E.Relative{v})) == v : Bool}

law opt_set_indent:
  for o: E.Opts
  for v: Bool
  {E.opt.indent(E.opts.set(o, E.AutoIndent{v})) == v : Bool}

law opt_set_shift:
  for o: E.Opts
  for v: Nat
  {E.opt.shift(E.opts.set(o, E.Shift{v})) == v : Nat}

law opt_set_hls:
  for o: E.Opts
  for v: Bool
  {E.opt.hls(E.opts.set(o, E.HlSearch{v})) == v : Bool}

law opt_set_ic:
  for o: E.Opts
  for v: Bool
  {E.opt.ic(E.opts.set(o, E.IgnoreCase{v})) == v : Bool}

law opt_set_scs:
  for o: E.Opts
  for v: Bool
  {E.opt.scs(E.opts.set(o, E.SmartCase{v})) == v : Bool}

law opt_set_ws:
  for o: E.Opts
  for v: Bool
  {E.opt.ws(E.opts.set(o, E.WrapScan{v})) == v : Bool}

law opt_set_et:
  for o: E.Opts
  for v: Bool
  {E.opt.et(E.opts.set(o, E.ExpandTab{v})) == v : Bool}

law opt_number_keeps_shift:
  for o: E.Opts
  for v: Bool
  {E.opt.shift(E.opts.set(o, E.Number{v})) == E.opt.shift(o) : Nat}

law opt_relative_keeps_number:
  for o: E.Opts
  for v: Bool
  {E.opt.number(E.opts.set(o, E.Relative{v})) == E.opt.number(o) : Bool}

law opt_indent_keeps_number:
  for o: E.Opts
  for v: Bool
  {E.opt.number(E.opts.set(o, E.AutoIndent{v})) == E.opt.number(o) : Bool}

law opt_shift_keeps_number:
  for o: E.Opts
  for v: Nat
  {E.opt.number(E.opts.set(o, E.Shift{v})) == E.opt.number(o) : Bool}

law opt_hls_keeps_number:
  for o: E.Opts
  for v: Bool
  {E.opt.number(E.opts.set(o, E.HlSearch{v})) == E.opt.number(o) : Bool}

law opt_ic_keeps_number:
  for o: E.Opts
  for v: Bool
  {E.opt.number(E.opts.set(o, E.IgnoreCase{v})) == E.opt.number(o) : Bool}

law opt_scs_keeps_number:
  for o: E.Opts
  for v: Bool
  {E.opt.number(E.opts.set(o, E.SmartCase{v})) == E.opt.number(o) : Bool}

law opt_ws_keeps_number:
  for o: E.Opts
  for v: Bool
  {E.opt.number(E.opts.set(o, E.WrapScan{v})) == E.opt.number(o) : Bool}

law opt_et_keeps_number:
  for o: E.Opts
  for v: Bool
  {E.opt.number(E.opts.set(o, E.ExpandTab{v})) == E.opt.number(o) : Bool}

4.17Counts and the case of letters in a pattern

A part zero times is nothing.

law times_zero:
  for r: R.Re
  for t: R.Re
  {R.times.re(0n, r, t) == t : R.Re}

law upto_zero:
  for r: R.Re
  {R.upto.re(0n, r) == R.Nul{} : R.Re}

law count_exact:
  for lo: Nat
  for hi: Nat
  for r: R.Re
  {R.count.re(lo, hi, 0n, r) == R.times.re(lo, r, R.Nul{}) : R.Re}

law count_open:
  for lo: Nat
  for hi: Nat
  for +r: R.Re
  {R.count.re(lo, hi, 2n, r) == R.times.re(lo, r, R.Many{r}) : R.Re}

law folds_c:
  for d: Bool
  {R.folds(1n, d) == True{} : Bool}

law folds_big_c:
  for d: Bool
  {R.folds(2n, d) == False{} : Bool}

law folds_none:
  for d: Bool
  {R.folds(0n, d) == d : Bool}

law fold_off:
  for r: R.Re
  {R.fold.if(False{}, r) == r : R.Re}

4.18Ranges, `&` and `:g`

An offset of zero is the line.

law shift_up_zero:
  for r: Nat
  {E.addr.shift(False{}, r, 0n) == r : Nat}

law shift_down_zero:
  for r: Nat
  {E.addr.shift(True{}, r, 0n) == r : Nat}

law again_same:
  for p: String
  for r: String
  for a: Bool
  for m: Nat
  for n: Nat
  {E.again.n(E.Subst{p, r, a, m}, n) == E.Subst{p, r, a, n} : E.Act}

law gkeep_zero:
  for ls: List<&2, String>
  for p: R.Pat
  for inv: Bool
  {B.gkeep(0n, ls, p, inv) == ls : List<&2, String>}

law gdel_zero:
  for p: R.Pat
  for inv: Bool
  for b: B.Buf
  {B.gdel(0n, p, inv, b) == B.home(b) : B.Buf}

law safe_gdel:
  for k: Nat
  for p: R.Pat
  for inv: Bool
  for g: S.Good
  {S.buf(S.gdel(k, p, inv, g)) == B.gdel(k, p, inv, S.buf(g)) : B.Buf}

4.19A macro is text

`q` keeps the keys of a macro as text in a register: one character for each key. K.pack makes the text and K.unpack gives the keys back. For each key that has no character of its own, the key comes back.

law pack_nil:
  {K.pack(Nil{}) == "" : String}

law unpack_nil:
  {K.unpack("") == Nil{} : List<&2, K.Key>}

law pack_enter:
  {K.unpack.k(K.pack.k(K.Enter{})) == K.Enter{} : K.Key}

law pack_esc:
  {K.unpack.k(K.pack.k(K.Esc{})) == K.Esc{} : K.Key}

law pack_back:
  {K.unpack.k(K.pack.k(K.Back{})) == K.Back{} : K.Key}

law pack_tab:
  {K.unpack.k(K.pack.k(K.Tab{})) == K.Tab{} : K.Key}

law pack_up:
  {K.unpack.k(K.pack.k(K.Up{})) == K.Up{} : K.Key}

law pack_down:
  {K.unpack.k(K.pack.k(K.Down{})) == K.Down{} : K.Key}

law pack_left:
  {K.unpack.k(K.pack.k(K.Left{})) == K.Left{} : K.Key}

law pack_right:
  {K.unpack.k(K.pack.k(K.Right{})) == K.Right{} : K.Key}

law pack_home:
  {K.unpack.k(K.pack.k(K.Home{})) == K.Home{} : K.Key}

law pack_end:
  {K.unpack.k(K.pack.k(K.End{})) == K.End{} : K.Key}

law pack_del:
  {K.unpack.k(K.pack.k(K.Del{})) == K.Del{} : K.Key}

law pack_pgup:
  {K.unpack.k(K.pack.k(K.PgUp{})) == K.PgUp{} : K.Key}

law pack_pgdn:
  {K.unpack.k(K.pack.k(K.PgDn{})) == K.PgDn{} : K.Key}

4.20More about registers, `U`, `r` and `.`

A yank of a block marks the unnamed register as a block.

law store_block:
  for e: E.Ed
  for text: String
  for lines: Bool
  for yank: Bool
  {E.regb(E.store.in(e, text, lines, True{}, yank, 0n)) == True{} : Bool}

law hole_keeps_block:
  for e: E.Ed
  for text: String
  for lines: Bool
  for block: Bool
  for yank: Bool
  {E.regb(E.store.in(e, text, lines, block, yank, 1n)) == E.regb(e) : Bool}

law line_undo_none:
  for same: Bool
  for text: String
  {E.line.undo(False{}, same, text) == E.Nop{} : E.Act}

law line_undo_other:
  for text: String
  {E.line.undo(True{}, False{}, text) == E.Nop{} : E.Act}

law usave_none:
  for e: E.Ed
  {E.usave(e, False{}) == e : E.Ed}

law swap_normal:
  for c: Char
  for n: Nat
  {E.swap.for(E.Normal{}, c, n) == E.swap.act(c, n) : E.Act}

law swap_visual:
  for line: Bool
  for c: Char
  for n: Nat
  {E.swap.for(E.Visual{line}, c, n) == E.VisOp{E.Fill{c}} : E.Act}

law dot_motion:
  for m: C.Move
  for k: E.Span
  for n: Nat
  for fin: E.Act
  {E.dot.of(E.Motion{m, k}, n, fin) == fin : E.Act}

law wrap_none:
  for a: E.Act
  {E.reg.wrap("", a) == a : E.Act}

law inreg_changes:
  for r: String
  for a: E.Act
  {E.changes(E.InReg{r, a}) == E.changes(a) : Bool}

law box_no_dollar:
  for c0: Nat
  for w: Nat
  for top: B.Buf
  for n: Nat
  {E.box.w(False{}, c0, w, top, n) == w : Nat}

law fill_nil:
  for n: Nat
  {B.fill.s("", n) == "" : String}

4.21Each option is apart from the other options

A change of one option changes no other option. There is one law for each pair of options.

law opt_set_tw:
  for o: E.Opts
  for v: Nat
  {E.opt.tw(E.opts.set(o, E.TextWidth{v})) == v : Nat}

law opt_number_keeps_relative:
  for o: E.Opts
  for v: Bool
  {E.opt.relative(E.opts.set(o, E.Number{v})) == E.opt.relative(o) : Bool}

law opt_number_keeps_indent:
  for o: E.Opts
  for v: Bool
  {E.opt.indent(E.opts.set(o, E.Number{v})) == E.opt.indent(o) : Bool}

law opt_number_keeps_hls:
  for o: E.Opts
  for v: Bool
  {E.opt.hls(E.opts.set(o, E.Number{v})) == E.opt.hls(o) : Bool}

law opt_number_keeps_ic:
  for o: E.Opts
  for v: Bool
  {E.opt.ic(E.opts.set(o, E.Number{v})) == E.opt.ic(o) : Bool}

law opt_number_keeps_scs:
  for o: E.Opts
  for v: Bool
  {E.opt.scs(E.opts.set(o, E.Number{v})) == E.opt.scs(o) : Bool}

law opt_number_keeps_ws:
  for o: E.Opts
  for v: Bool
  {E.opt.ws(E.opts.set(o, E.Number{v})) == E.opt.ws(o) : Bool}

law opt_number_keeps_et:
  for o: E.Opts
  for v: Bool
  {E.opt.et(E.opts.set(o, E.Number{v})) == E.opt.et(o) : Bool}

law opt_number_keeps_tw:
  for o: E.Opts
  for v: Bool
  {E.opt.tw(E.opts.set(o, E.Number{v})) == E.opt.tw(o) : Nat}

law opt_relative_keeps_indent:
  for o: E.Opts
  for v: Bool
  {E.opt.indent(E.opts.set(o, E.Relative{v})) == E.opt.indent(o) : Bool}

law opt_relative_keeps_shift:
  for o: E.Opts
  for v: Bool
  {E.opt.shift(E.opts.set(o, E.Relative{v})) == E.opt.shift(o) : Nat}

law opt_relative_keeps_hls:
  for o: E.Opts
  for v: Bool
  {E.opt.hls(E.opts.set(o, E.Relative{v})) == E.opt.hls(o) : Bool}

law opt_relative_keeps_ic:
  for o: E.Opts
  for v: Bool
  {E.opt.ic(E.opts.set(o, E.Relative{v})) == E.opt.ic(o) : Bool}

law opt_relative_keeps_scs:
  for o: E.Opts
  for v: Bool
  {E.opt.scs(E.opts.set(o, E.Relative{v})) == E.opt.scs(o) : Bool}

law opt_relative_keeps_ws:
  for o: E.Opts
  for v: Bool
  {E.opt.ws(E.opts.set(o, E.Relative{v})) == E.opt.ws(o) : Bool}

law opt_relative_keeps_et:
  for o: E.Opts
  for v: Bool
  {E.opt.et(E.opts.set(o, E.Relative{v})) == E.opt.et(o) : Bool}

law opt_relative_keeps_tw:
  for o: E.Opts
  for v: Bool
  {E.opt.tw(E.opts.set(o, E.Relative{v})) == E.opt.tw(o) : Nat}

law opt_indent_keeps_relative:
  for o: E.Opts
  for v: Bool
  {E.opt.relative(E.opts.set(o, E.AutoIndent{v})) == E.opt.relative(o) : Bool}

law opt_indent_keeps_shift:
  for o: E.Opts
  for v: Bool
  {E.opt.shift(E.opts.set(o, E.AutoIndent{v})) == E.opt.shift(o) : Nat}

law opt_indent_keeps_hls:
  for o: E.Opts
  for v: Bool
  {E.opt.hls(E.opts.set(o, E.AutoIndent{v})) == E.opt.hls(o) : Bool}

law opt_indent_keeps_ic:
  for o: E.Opts
  for v: Bool
  {E.opt.ic(E.opts.set(o, E.AutoIndent{v})) == E.opt.ic(o) : Bool}

law opt_indent_keeps_scs:
  for o: E.Opts
  for v: Bool
  {E.opt.scs(E.opts.set(o, E.AutoIndent{v})) == E.opt.scs(o) : Bool}

law opt_indent_keeps_ws:
  for o: E.Opts
  for v: Bool
  {E.opt.ws(E.opts.set(o, E.AutoIndent{v})) == E.opt.ws(o) : Bool}

law opt_indent_keeps_et:
  for o: E.Opts
  for v: Bool
  {E.opt.et(E.opts.set(o, E.AutoIndent{v})) == E.opt.et(o) : Bool}

law opt_indent_keeps_tw:
  for o: E.Opts
  for v: Bool
  {E.opt.tw(E.opts.set(o, E.AutoIndent{v})) == E.opt.tw(o) : Nat}

law opt_shift_keeps_relative:
  for o: E.Opts
  for v: Nat
  {E.opt.relative(E.opts.set(o, E.Shift{v})) == E.opt.relative(o) : Bool}

law opt_shift_keeps_indent:
  for o: E.Opts
  for v: Nat
  {E.opt.indent(E.opts.set(o, E.Shift{v})) == E.opt.indent(o) : Bool}

law opt_shift_keeps_hls:
  for o: E.Opts
  for v: Nat
  {E.opt.hls(E.opts.set(o, E.Shift{v})) == E.opt.hls(o) : Bool}

law opt_shift_keeps_ic:
  for o: E.Opts
  for v: Nat
  {E.opt.ic(E.opts.set(o, E.Shift{v})) == E.opt.ic(o) : Bool}

law opt_shift_keeps_scs:
  for o: E.Opts
  for v: Nat
  {E.opt.scs(E.opts.set(o, E.Shift{v})) == E.opt.scs(o) : Bool}

law opt_shift_keeps_ws:
  for o: E.Opts
  for v: Nat
  {E.opt.ws(E.opts.set(o, E.Shift{v})) == E.opt.ws(o) : Bool}

law opt_shift_keeps_et:
  for o: E.Opts
  for v: Nat
  {E.opt.et(E.opts.set(o, E.Shift{v})) == E.opt.et(o) : Bool}

law opt_shift_keeps_tw:
  for o: E.Opts
  for v: Nat
  {E.opt.tw(E.opts.set(o, E.Shift{v})) == E.opt.tw(o) : Nat}

law opt_hls_keeps_relative:
  for o: E.Opts
  for v: Bool
  {E.opt.relative(E.opts.set(o, E.HlSearch{v})) == E.opt.relative(o) : Bool}

law opt_hls_keeps_indent:
  for o: E.Opts
  for v: Bool
  {E.opt.indent(E.opts.set(o, E.HlSearch{v})) == E.opt.indent(o) : Bool}

law opt_hls_keeps_shift:
  for o: E.Opts
  for v: Bool
  {E.opt.shift(E.opts.set(o, E.HlSearch{v})) == E.opt.shift(o) : Nat}

law opt_hls_keeps_ic:
  for o: E.Opts
  for v: Bool
  {E.opt.ic(E.opts.set(o, E.HlSearch{v})) == E.opt.ic(o) : Bool}

law opt_hls_keeps_scs:
  for o: E.Opts
  for v: Bool
  {E.opt.scs(E.opts.set(o, E.HlSearch{v})) == E.opt.scs(o) : Bool}

law opt_hls_keeps_ws:
  for o: E.Opts
  for v: Bool
  {E.opt.ws(E.opts.set(o, E.HlSearch{v})) == E.opt.ws(o) : Bool}

law opt_hls_keeps_et:
  for o: E.Opts
  for v: Bool
  {E.opt.et(E.opts.set(o, E.HlSearch{v})) == E.opt.et(o) : Bool}

law opt_hls_keeps_tw:
  for o: E.Opts
  for v: Bool
  {E.opt.tw(E.opts.set(o, E.HlSearch{v})) == E.opt.tw(o) : Nat}

law opt_ic_keeps_relative:
  for o: E.Opts
  for v: Bool
  {E.opt.relative(E.opts.set(o, E.IgnoreCase{v})) == E.opt.relative(o) : Bool}

law opt_ic_keeps_indent:
  for o: E.Opts
  for v: Bool
  {E.opt.indent(E.opts.set(o, E.IgnoreCase{v})) == E.opt.indent(o) : Bool}

law opt_ic_keeps_shift:
  for o: E.Opts
  for v: Bool
  {E.opt.shift(E.opts.set(o, E.IgnoreCase{v})) == E.opt.shift(o) : Nat}

law opt_ic_keeps_hls:
  for o: E.Opts
  for v: Bool
  {E.opt.hls(E.opts.set(o, E.IgnoreCase{v})) == E.opt.hls(o) : Bool}

law opt_ic_keeps_scs:
  for o: E.Opts
  for v: Bool
  {E.opt.scs(E.opts.set(o, E.IgnoreCase{v})) == E.opt.scs(o) : Bool}

law opt_ic_keeps_ws:
  for o: E.Opts
  for v: Bool
  {E.opt.ws(E.opts.set(o, E.IgnoreCase{v})) == E.opt.ws(o) : Bool}

law opt_ic_keeps_et:
  for o: E.Opts
  for v: Bool
  {E.opt.et(E.opts.set(o, E.IgnoreCase{v})) == E.opt.et(o) : Bool}

law opt_ic_keeps_tw:
  for o: E.Opts
  for v: Bool
  {E.opt.tw(E.opts.set(o, E.IgnoreCase{v})) == E.opt.tw(o) : Nat}

law opt_scs_keeps_relative:
  for o: E.Opts
  for v: Bool
  {E.opt.relative(E.opts.set(o, E.SmartCase{v})) == E.opt.relative(o) : Bool}

law opt_scs_keeps_indent:
  for o: E.Opts
  for v: Bool
  {E.opt.indent(E.opts.set(o, E.SmartCase{v})) == E.opt.indent(o) : Bool}

law opt_scs_keeps_shift:
  for o: E.Opts
  for v: Bool
  {E.opt.shift(E.opts.set(o, E.SmartCase{v})) == E.opt.shift(o) : Nat}

law opt_scs_keeps_hls:
  for o: E.Opts
  for v: Bool
  {E.opt.hls(E.opts.set(o, E.SmartCase{v})) == E.opt.hls(o) : Bool}

law opt_scs_keeps_ic:
  for o: E.Opts
  for v: Bool
  {E.opt.ic(E.opts.set(o, E.SmartCase{v})) == E.opt.ic(o) : Bool}

law opt_scs_keeps_ws:
  for o: E.Opts
  for v: Bool
  {E.opt.ws(E.opts.set(o, E.SmartCase{v})) == E.opt.ws(o) : Bool}

law opt_scs_keeps_et:
  for o: E.Opts
  for v: Bool
  {E.opt.et(E.opts.set(o, E.SmartCase{v})) == E.opt.et(o) : Bool}

law opt_scs_keeps_tw:
  for o: E.Opts
  for v: Bool
  {E.opt.tw(E.opts.set(o, E.SmartCase{v})) == E.opt.tw(o) : Nat}

law opt_ws_keeps_relative:
  for o: E.Opts
  for v: Bool
  {E.opt.relative(E.opts.set(o, E.WrapScan{v})) == E.opt.relative(o) : Bool}

law opt_ws_keeps_indent:
  for o: E.Opts
  for v: Bool
  {E.opt.indent(E.opts.set(o, E.WrapScan{v})) == E.opt.indent(o) : Bool}

law opt_ws_keeps_shift:
  for o: E.Opts
  for v: Bool
  {E.opt.shift(E.opts.set(o, E.WrapScan{v})) == E.opt.shift(o) : Nat}

law opt_ws_keeps_hls:
  for o: E.Opts
  for v: Bool
  {E.opt.hls(E.opts.set(o, E.WrapScan{v})) == E.opt.hls(o) : Bool}

law opt_ws_keeps_ic:
  for o: E.Opts
  for v: Bool
  {E.opt.ic(E.opts.set(o, E.WrapScan{v})) == E.opt.ic(o) : Bool}

law opt_ws_keeps_scs:
  for o: E.Opts
  for v: Bool
  {E.opt.scs(E.opts.set(o, E.WrapScan{v})) == E.opt.scs(o) : Bool}

law opt_ws_keeps_et:
  for o: E.Opts
  for v: Bool
  {E.opt.et(E.opts.set(o, E.WrapScan{v})) == E.opt.et(o) : Bool}

law opt_ws_keeps_tw:
  for o: E.Opts
  for v: Bool
  {E.opt.tw(E.opts.set(o, E.WrapScan{v})) == E.opt.tw(o) : Nat}

law opt_et_keeps_relative:
  for o: E.Opts
  for v: Bool
  {E.opt.relative(E.opts.set(o, E.ExpandTab{v})) == E.opt.relative(o) : Bool}

law opt_et_keeps_indent:
  for o: E.Opts
  for v: Bool
  {E.opt.indent(E.opts.set(o, E.ExpandTab{v})) == E.opt.indent(o) : Bool}

law opt_et_keeps_shift:
  for o: E.Opts
  for v: Bool
  {E.opt.shift(E.opts.set(o, E.ExpandTab{v})) == E.opt.shift(o) : Nat}

law opt_et_keeps_hls:
  for o: E.Opts
  for v: Bool
  {E.opt.hls(E.opts.set(o, E.ExpandTab{v})) == E.opt.hls(o) : Bool}

law opt_et_keeps_ic:
  for o: E.Opts
  for v: Bool
  {E.opt.ic(E.opts.set(o, E.ExpandTab{v})) == E.opt.ic(o) : Bool}

law opt_et_keeps_scs:
  for o: E.Opts
  for v: Bool
  {E.opt.scs(E.opts.set(o, E.ExpandTab{v})) == E.opt.scs(o) : Bool}

law opt_et_keeps_ws:
  for o: E.Opts
  for v: Bool
  {E.opt.ws(E.opts.set(o, E.ExpandTab{v})) == E.opt.ws(o) : Bool}

law opt_et_keeps_tw:
  for o: E.Opts
  for v: Bool
  {E.opt.tw(E.opts.set(o, E.ExpandTab{v})) == E.opt.tw(o) : Nat}

law opt_tw_keeps_number:
  for o: E.Opts
  for v: Nat
  {E.opt.number(E.opts.set(o, E.TextWidth{v})) == E.opt.number(o) : Bool}

law opt_tw_keeps_relative:
  for o: E.Opts
  for v: Nat
  {E.opt.relative(E.opts.set(o, E.TextWidth{v})) == E.opt.relative(o) : Bool}

law opt_tw_keeps_indent:
  for o: E.Opts
  for v: Nat
  {E.opt.indent(E.opts.set(o, E.TextWidth{v})) == E.opt.indent(o) : Bool}

law opt_tw_keeps_shift:
  for o: E.Opts
  for v: Nat
  {E.opt.shift(E.opts.set(o, E.TextWidth{v})) == E.opt.shift(o) : Nat}

law opt_tw_keeps_hls:
  for o: E.Opts
  for v: Nat
  {E.opt.hls(E.opts.set(o, E.TextWidth{v})) == E.opt.hls(o) : Bool}

law opt_tw_keeps_ic:
  for o: E.Opts
  for v: Nat
  {E.opt.ic(E.opts.set(o, E.TextWidth{v})) == E.opt.ic(o) : Bool}

law opt_tw_keeps_scs:
  for o: E.Opts
  for v: Nat
  {E.opt.scs(E.opts.set(o, E.TextWidth{v})) == E.opt.scs(o) : Bool}

law opt_tw_keeps_ws:
  for o: E.Opts
  for v: Nat
  {E.opt.ws(E.opts.set(o, E.TextWidth{v})) == E.opt.ws(o) : Bool}

law opt_tw_keeps_et:
  for o: E.Opts
  for v: Nat
  {E.opt.et(E.opts.set(o, E.TextWidth{v})) == E.opt.et(o) : Bool}

4.22Tags, the format operator and word completion

With no open tag or no close tag, there is no tag object.

law tag_none:
  for around: Bool
  for nb: Nat
  for no: Nat
  for nf: Nat
  for nc: Nat
  {B.tag.range(False{}, around, nb, no, nf, nc) == B.none() : B.Range}

law tag_around:
  for nb: Nat
  for no: Nat
  for nf: Nat
  for nc: Nat
  {B.tag.range(True{}, True{}, nb, no, nf, nc) == B.Range{True{}, nb, 0n, Nat.add(nb, Nat.add(nf, nc))} : B.Range}

law tag_fwd_end:
  for depth: Nat
  for intag: Bool
  for pos: Nat
  {B.tag.fwd(Nil{}, depth, intag, pos) == 0n : Nat}

law tag_bwd_end:
  for depth: Nat
  for slash: Bool
  for self: Bool
  for pos: Nat
  {B.tag.bwd(Nil{}, depth, slash, self, pos) == 0n : Nat}

law tag_fwd_close:
  for t: List<&2, B.TC>
  for intag: Bool
  for pos: Nat
  {B.tag.fwd(B.TLt{} <> B.TSlash{} <> t, 0n, intag, pos) == 1n+pos : Nat}

law tag_left_out:
  for t: List<&2, B.TC>
  for slash: Bool
  for pos: Nat
  {B.tag.left(B.TGt{} <> t, slash, pos) == 0n : Nat}

law tag_right_close:
  for t: List<&2, B.TC>
  {B.tag.right(B.TLt{} <> B.TSlash{} <> t) == 0n : Nat}

law tw_default:
  {E.tw.of(0n) == 79n : Nat}

law tw_set:
  for p: Nat
  {E.tw.of(1n+p) == 1n+p : Nat}

law format_rows:
  {E.is_shift(E.Format{}) == True{} : Bool}

law format_twice:
  {E.same(E.Format{}, E.Format{}) == True{} : Bool}

law flow_fits_end:
  for len: Nat
  for w: Nat
  {B.flow.fits(Nil{}, len, w) == True{} : Bool}

law flow_last:
  for w: Nat
  for cur: String
  for len: Nat
  for fits: Bool
  for ind: String
  {B.flow.go(Nil{}, w, cur, len, fits, ind) == [cur] : List<&2, String>}

law flow_none:
  for w: Nat
  {B.flow.paras(Nil{}, w, Nil{}) == Nil{} : List<&2, String>}

law flow_words_none:
  {B.flow.words(Nil{}) == Nil{} : List<&2, String>}

law flow_blank:
  for x: String
  for t: List<&2, B.FL>
  for w: Nat
  {B.flow.paras(B.FL{True{}, x} <> t, w, Nil{}) == "" <> B.flow.paras(t, w, Nil{}) : List<&2, String>}

law complete_prev_first:
  for n: Nat
  {E.complete.next(True{}, 0n, n) == n : Nat}

law complete_none:
  for e: E.Ed
  for p: String
  for del: Nat
  for cs: List<&2, String>
  for k: Nat
  {E.complete.at(e, p, del, cs, k, 0n) == E.set_msg(e, "no completion") : E.Ed}

law complete_no_word:
  for e: E.Ed
  for back: Bool
  {E.complete.new(e, back, "") == E.set_msg(e, "no word to complete") : E.Ed}

law typed_not_complete:
  for x: C.Edit
  {E.is_complete(E.Typed{x}) == 0n : Nat}

law cand_skip:
  for w: String
  for acc: List<&2, String>
  {B.cand.add(False{}, w, acc) == acc : List<&2, String>}

law cand_line_end:
  for p: String
  for acc: List<&2, String>
  {B.cand.line(Nil{}, p, acc) == acc : List<&2, String>}

law words_none:
  {B.words.go(Nil{}, "") == Nil{} : List<&2, String>}

law words_skip:
  for c: Char
  for t: List<&2, B.WC>
  {B.words.go(B.WC{False{}, c} <> t, "") == B.words.go(t, "") : List<&2, String>}

4.23The command line

The command line has a cursor, a history and a tab key. These are the rules at its edges. An empty line does not go in the history.

law hist_add_empty:
  for hs: List<&2, String>
  {E.hist.add("", hs) == hs : List<&2, String>}

law hist_same_nil:
  for line: String
  {E.hist.same(Nil{}, line) == False{} : Bool}

law hist_go_none:
  for e: E.Ed
  for k: Nat
  for hs: List<&2, String>
  {E.hist.go(e, k, False{}, hs) == e : E.Ed}

law hist_keep_later:
  for e: E.Ed
  for p: Nat
  {E.hist.keep(e, 1n+p) == e : E.Ed}

law tab_off:
  for e: E.Ed
  for on: Bool
  {E.tab.on(e, on, False{}) == e : E.Ed}

law tab_no_match:
  for e: E.Ed
  for head: String
  for typed: String
  {E.tab.fill(e, head, Nil{}, typed) == E.set_msg(e, "no match") : E.Ed}

law tab_kind_word:
  {E.tab.kind("") == 0n : Nat}

law starting_nil:
  for p: String
  {E.starting(Nil{}, p) == Nil{} : List<&2, String>}

law starts_skip:
  for x: String
  for r: List<&2, String>
  {E.starts.keep(False{}, x, r) == r : List<&2, String>}

law starts_keep:
  for x: String
  for r: List<&2, String>
  {E.starts.keep(True{}, x, r) == x <> r : List<&2, String>}

law upto_stop:
  for c: Char
  for rest: String
  {E.upto.c(True{}, c, rest) == "" : String}

law upto_nil:
  {E.upto.sp("") == "" : String}

law cmd_left_start:
  for e: E.Ed
  {E.cmd.left(e, "") == e : E.Ed}

law cmd_right_end:
  for e: E.Ed
  {E.cmd.right(e, "") == e : E.Ed}

law cmdline_back_start:
  for e: E.Ed
  {E.cmdline.back(e, "", False{}) == e : E.Ed}

law cmdline_page_up:
  for e: E.Ed
  for search: Bool
  for back: Bool
  {E.cmdline.key(e, K.PgUp{}, search, back) == e : E.Ed}

law cmdline_page_down:
  for e: E.Ed
  for search: Bool
  for back: Bool
  {E.cmdline.key(e, K.PgDn{}, search, back) == e : E.Ed}

law head_stop:
  for c: Char
  for rest: String
  {E.head.c(True{}, c, rest) == "" : String}

law head_nil:
  {E.head.line("") == "" : String}

law cmd_close_empty:
  for e: E.Ed
  {E.cmd.line(E.cmd.close(e)) == "" : String}

law fresh_no_sheet:
  for e: E.Ed
  {E.sheet(E.fresh(e)) == Nil{} : List<&2, String>}

4.24Shell commands and files

`:!`, `:r`, `:normal` and `:e` ask the shell for work. The answer changes the text only when the work was done. With no file name, a shell command does not change.

law shell_no_file:
  for cmd: String
  {E.shell.cmd(cmd, "") == cmd : String}

law shell_pct:
  for c: Char
  for rest: String
  for file: String
  {E.shell.c(True{}, c, rest, file) == String.append(file, rest) : String}

law shell_plain:
  for c: Char
  for rest: String
  for file: String
  {E.shell.c(False{}, c, rest, file) == SCon{c, rest} : String}

law shell_nil:
  for file: String
  {E.shell.go("", file) == "" : String}

law open_refuses:
  for e: E.Ed
  for path: String
  {E.open.same(e, path, False{}, True{}) == E.set_msg(e, "no write since the last change (:e! discards it)") : E.Ed}

law open_force:
  for e: E.Ed
  for path: String
  for dirty: Bool
  {E.open.same(e, path, True{}, dirty) == E.open.to(e, path) : E.Ed}

law open_clean:
  for e: E.Ed
  for path: String
  {E.open.same(e, path, False{}, False{}) == E.open.to(e, path) : E.Ed}

law open_no_name:
  for e: E.Ed
  {E.open.path(e, "") == E.set_msg(e, "no file name (:e <file>)") : E.Ed}

law norm_none:
  for lo: Nat
  for keys: String
  {E.norm.text(0n, lo, keys) == "" : String}

law bang_alone:
  for b: E.Addr
  for cmd: String
  {E.bang.act(E.ANone{}, b, cmd) == Some{E.Run{cmd}} : Maybe<&2, E.Act>}

law read_alone:
  for b: E.Addr
  for arg: String
  {E.read.act(E.ANone{}, b, arg) == Some{E.ReadIn{arg, False{}}} : Maybe<&2, E.Act>}

law read_zero:
  for b: E.Addr
  for arg: String
  {E.read.line(0n, b, arg) == Some{E.Both{E.Motion{C.Do{C.Top{}}, E.Rows{}}, E.ReadIn{arg, True{}}}} : Maybe<&2, E.Act>}

law not_normal:
  for a: E.Addr
  for b: E.Addr
  for text: String
  {E.norm.act(a, b, text, False{}, False{}) == None{} : Maybe<&2, E.Act>}

law put_lines_none:
  for e: E.Ed
  for above: Bool
  {E.put.lines(e, "", above) == E.set_msg(e, "there is no text to read") : E.Ed}

law sheet_one:
  for e: E.Ed
  for x: String
  {E.sheet.of(e, [x]) == E.set_msg(e, x) : E.Ed}

law sheet_none:
  for e: E.Ed
  {E.sheet.of(e, Nil{}) == E.set_msg(e, "the command gave no output") : E.Ed}

law filter_fail_keeps_text:
  for e: E.Ed
  for c: Nat
  for h: Nat
  for n: Nat
  for out: String
  for err: String
  {E.buf(E.shelled.code(e, 1n+c, 1n+h, n, out, err)) == E.buf(e) : B.Buf}

law chomp_keeps:
  for text: String
  {E.chomp.if(False{}, text) == text : String}

law flat_nl:
  for c: Char
  for r: String
  {E.flat.c(True{}, c, r) == SCon{'^', SCon{'J', r}} : String}

law flat_nil:
  {E.flat("") == "" : String}

law marks_none:
  {E.marks.act(Nil{}) == E.Msg{"there are no marks"} : E.Act}

law glob_none:
  {E.glob.lines("") == Nil{} : List<&2, String>}

4.25The last line end, and the line ends of DOS

edict does not show the last line end of a file as an empty line, and it does not show the carriage returns of a DOS file. These laws say that nothing is lost: the file that edict writes is the file that it read.

law eol_put_cons:
  for on: Bool
  for d: String
  for xs: List<&2, String>
  {B.eol.put(on, d <> xs) == d <> B.eol.put(on, xs) : List<&2, String>}

law eol_chop:
  for ds: List<&2, String>
  {B.eol.put(B.eol.go(ds), B.chop.go(ds)) == ds : List<&2, String>}

law hide_show:
  for b: B.Buf
  {B.show(B.eol.of(b), B.hide(b)) == b : B.Buf}

law file_round_trip:
  for +s: String
  {B.text(B.show(B.eol.of(B.load(s)), B.hide(B.load(s)))) == s : String}

law eol_kind_empty:
  {E.eol.kind(0n) == B.Eol{True{}, True{}} : B.Eol}

law eol_kind_end:
  {E.eol.kind(1n) == B.Eol{False{}, True{}} : B.Eol}

law eol_kind_none:
  {E.eol.kind(2n) == B.Eol{False{}, False{}} : B.Eol}

law eol_keeps:
  for on: Bool
  for single: Bool
  {B.eol.want(False{}, on, single) == on : Bool}

law eol_new_text:
  for on: Bool
  {B.eol.want(True{}, on, False{}) == on : Bool}

law eol_of_empty:
  for on: Bool
  {B.eol.new(True{}, on) == B.Eol{True{}, True{}} : B.Eol}

law emptied_keeps_on:
  for empty: Bool
  for on: Bool
  {E.emptied.eol(B.Eol{empty, on}) == B.Eol{True{}, on} : B.Eol}

law emptied_not:
  for e: E.Ed
  {E.emptied.if(e, False{}) == e : E.Ed}

law eol_still_empty:
  for on: Bool
  {B.eol.want(True{}, on, True{}) == False{} : Bool}

law cr_line:
  for s: String
  {B.cr.strip1(B.cr.add1(s)) == s : String}

law cr_lines:
  for ls: List<&2, String>
  {B.cr.strips(B.cr.adds(ls)) == ls : List<&2, String>}

law cr_buf:
  for b: B.Buf
  {B.cr.strip(B.cr.add(b)) == b : B.Buf}

law cr_add_ends:
  for s: String
  {B.cr.ends(B.cr.add1(s)) == True{} : Bool}

law cr_all_stop:
  for x: String
  for t: List<&2, String>
  {B.cr.all(x <> t, False{}) == False{} : Bool}

law cr_all_end:
  for ok: Bool
  {B.cr.all(Nil{}, ok) == ok : Bool}

law lines_text:
  for +b: B.Buf
  {B.unlines(B.lines(b)) == B.text(b) : String}

law loadf_load:
  for +s: String
  {B.loadf(s) == B.load(s) : B.Buf}

law sep_unix:
  {E.sep.of(False{}) == "\n" : String}

law sep_dos:
  {E.sep.of(True{}) == "\r\n" : String}

law tail_none:
  {E.tail.of(False{}, False{}) == "" : String}

law tail_dos:
  {E.tail.of(True{}, True{}) == "\r\n" : String}

4.26A write does not lose the work of a different program

E.may.write gives 0 when edict can write the file. `:w!` always writes.

law write_force:
  for there: Bool
  for same: Bool
  for known: Bool
  for eq: Bool
  {E.may.write(True{}, there, same, known, eq) == 0n : Nat}

law write_new:
  for same: Bool
  for known: Bool
  for eq: Bool
  {E.may.write(False{}, False{}, same, known, eq) == 0n : Nat}

law write_other:
  for known: Bool
  for eq: Bool
  {E.may.write(False{}, True{}, False{}, known, eq) == 2n : Nat}

law write_same:
  {E.may.write(False{}, True{}, True{}, True{}, True{}) == 0n : Nat}

law write_changed:
  for known: Bool
  {E.may.write(False{}, True{}, True{}, known, False{}) == 1n : Nat}

law write_appeared:
  for eq: Bool
  {E.may.write(False{}, True{}, True{}, False{}, eq) == 1n : Nat}

law on_disk_keeps_text:
  for e: E.Ed
  for sz: Maybe<&2, Nat>
  {E.buf(E.on_disk(e, sz)) == E.buf(e) : B.Buf}

law note_noeol:
  {E.note.eol(B.Eol{False{}, False{}}) == " [noeol]" : String}

law note_one_byte:
  {E.note.bytes(1n) == "1 byte" : String}

law ff_wrong:
  {E.ff.act(False{}, False{}) == E.Msg{"fileformat is dos or unix: ff=unix"} : E.Act}

4.27The swap file

edict writes a copy of the text while you type. The copy is a request to the shell: it changes no text. With the count of the keys below its limit, there is no swap file.

law swap_not_due:
  for e: E.Ed
  {E.swap.due(e, False{}) == e : E.Ed}

law swap_clean:
  for e: E.Ed
  {E.swap.ok(e, False{}) == e : E.Ed}

law swap_keeps_text:
  for e: E.Ed
  for ok: Bool
  {E.buf(E.swap.ok(e, ok)) == E.buf(e) : B.Buf}

law swap_count_clean:
  for n: Nat
  {E.swap.count(False{}, n) == n : Nat}

law swap_count_dirty:
  for n: Nat
  {E.swap.count(True{}, n) == 1n+n : Nat}

law fresh_keeps_text:
  for e: E.Ed
  {E.buf(E.fresh(e)) == E.buf(e) : B.Buf}

law settle_keeps_text:
  for e: E.Ed
  for vert: Bool
  for keep: Bool
  {E.buf(E.settle(e, vert, keep)) == E.buf(e) : B.Buf}

law settle_no_register:
  for e: E.Ed
  for vert: Bool
  for keep: Bool
  {E.rsel(E.settle(e, vert, keep)) == "" : String}

law fit_same:
  for e: E.Ed
  for t: Nat
  for l: Nat
  {E.fit.set(e, t, l, True{}) == e : E.Ed}

law swap_done_keeps_text:
  for e: E.Ed
  {E.buf(E.swap.done(e)) == E.buf(e) : B.Buf}

law swap_none_found:
  for e: E.Ed
  {E.swap.found(e, False{}) == e : E.Ed}

law swap_gone:
  for e: E.Ed
  {E.swapped(E.swap.gone(e)) == False{} : Bool}

law idle_is_idle:
  {E.is_idle(E.Idle{}) == True{} : Bool}

4.28Search as you type, and the scroll margin

law opt_set_inc:
  for o: E.Opts
  for v: Bool
  {E.opt.inc(E.opts.set(o, E.IncSearch{v})) == v : Bool}

law opt_set_so:
  for o: E.Opts
  for v: Nat
  {E.opt.so(E.opts.set(o, E.ScrollOff{v})) == v : Nat}

law opt_number_keeps_inc:
  for o: E.Opts
  for v: Bool
  {E.opt.inc(E.opts.set(o, E.Number{v})) == E.opt.inc(o) : Bool}

law opt_number_keeps_so:
  for o: E.Opts
  for v: Bool
  {E.opt.so(E.opts.set(o, E.Number{v})) == E.opt.so(o) : Nat}

law opt_relative_keeps_inc:
  for o: E.Opts
  for v: Bool
  {E.opt.inc(E.opts.set(o, E.Relative{v})) == E.opt.inc(o) : Bool}

law opt_relative_keeps_so:
  for o: E.Opts
  for v: Bool
  {E.opt.so(E.opts.set(o, E.Relative{v})) == E.opt.so(o) : Nat}

law opt_indent_keeps_inc:
  for o: E.Opts
  for v: Bool
  {E.opt.inc(E.opts.set(o, E.AutoIndent{v})) == E.opt.inc(o) : Bool}

law opt_indent_keeps_so:
  for o: E.Opts
  for v: Bool
  {E.opt.so(E.opts.set(o, E.AutoIndent{v})) == E.opt.so(o) : Nat}

law opt_shift_keeps_inc:
  for o: E.Opts
  for v: Nat
  {E.opt.inc(E.opts.set(o, E.Shift{v})) == E.opt.inc(o) : Bool}

law opt_shift_keeps_so:
  for o: E.Opts
  for v: Nat
  {E.opt.so(E.opts.set(o, E.Shift{v})) == E.opt.so(o) : Nat}

law opt_hls_keeps_inc:
  for o: E.Opts
  for v: Bool
  {E.opt.inc(E.opts.set(o, E.HlSearch{v})) == E.opt.inc(o) : Bool}

law opt_hls_keeps_so:
  for o: E.Opts
  for v: Bool
  {E.opt.so(E.opts.set(o, E.HlSearch{v})) == E.opt.so(o) : Nat}

law opt_ic_keeps_inc:
  for o: E.Opts
  for v: Bool
  {E.opt.inc(E.opts.set(o, E.IgnoreCase{v})) == E.opt.inc(o) : Bool}

law opt_ic_keeps_so:
  for o: E.Opts
  for v: Bool
  {E.opt.so(E.opts.set(o, E.IgnoreCase{v})) == E.opt.so(o) : Nat}

law opt_scs_keeps_inc:
  for o: E.Opts
  for v: Bool
  {E.opt.inc(E.opts.set(o, E.SmartCase{v})) == E.opt.inc(o) : Bool}

law opt_scs_keeps_so:
  for o: E.Opts
  for v: Bool
  {E.opt.so(E.opts.set(o, E.SmartCase{v})) == E.opt.so(o) : Nat}

law opt_ws_keeps_inc:
  for o: E.Opts
  for v: Bool
  {E.opt.inc(E.opts.set(o, E.WrapScan{v})) == E.opt.inc(o) : Bool}

law opt_ws_keeps_so:
  for o: E.Opts
  for v: Bool
  {E.opt.so(E.opts.set(o, E.WrapScan{v})) == E.opt.so(o) : Nat}

law opt_et_keeps_inc:
  for o: E.Opts
  for v: Bool
  {E.opt.inc(E.opts.set(o, E.ExpandTab{v})) == E.opt.inc(o) : Bool}

law opt_et_keeps_so:
  for o: E.Opts
  for v: Bool
  {E.opt.so(E.opts.set(o, E.ExpandTab{v})) == E.opt.so(o) : Nat}

law opt_tw_keeps_inc:
  for o: E.Opts
  for v: Nat
  {E.opt.inc(E.opts.set(o, E.TextWidth{v})) == E.opt.inc(o) : Bool}

law opt_tw_keeps_so:
  for o: E.Opts
  for v: Nat
  {E.opt.so(E.opts.set(o, E.TextWidth{v})) == E.opt.so(o) : Nat}

law opt_inc_keeps_number:
  for o: E.Opts
  for v: Bool
  {E.opt.number(E.opts.set(o, E.IncSearch{v})) == E.opt.number(o) : Bool}

law opt_inc_keeps_relative:
  for o: E.Opts
  for v: Bool
  {E.opt.relative(E.opts.set(o, E.IncSearch{v})) == E.opt.relative(o) : Bool}

law opt_inc_keeps_indent:
  for o: E.Opts
  for v: Bool
  {E.opt.indent(E.opts.set(o, E.IncSearch{v})) == E.opt.indent(o) : Bool}

law opt_inc_keeps_shift:
  for o: E.Opts
  for v: Bool
  {E.opt.shift(E.opts.set(o, E.IncSearch{v})) == E.opt.shift(o) : Nat}

law opt_inc_keeps_hls:
  for o: E.Opts
  for v: Bool
  {E.opt.hls(E.opts.set(o, E.IncSearch{v})) == E.opt.hls(o) : Bool}

law opt_inc_keeps_ic:
  for o: E.Opts
  for v: Bool
  {E.opt.ic(E.opts.set(o, E.IncSearch{v})) == E.opt.ic(o) : Bool}

law opt_inc_keeps_scs:
  for o: E.Opts
  for v: Bool
  {E.opt.scs(E.opts.set(o, E.IncSearch{v})) == E.opt.scs(o) : Bool}

law opt_inc_keeps_ws:
  for o: E.Opts
  for v: Bool
  {E.opt.ws(E.opts.set(o, E.IncSearch{v})) == E.opt.ws(o) : Bool}

law opt_inc_keeps_et:
  for o: E.Opts
  for v: Bool
  {E.opt.et(E.opts.set(o, E.IncSearch{v})) == E.opt.et(o) : Bool}

law opt_inc_keeps_tw:
  for o: E.Opts
  for v: Bool
  {E.opt.tw(E.opts.set(o, E.IncSearch{v})) == E.opt.tw(o) : Nat}

law opt_inc_keeps_so:
  for o: E.Opts
  for v: Bool
  {E.opt.so(E.opts.set(o, E.IncSearch{v})) == E.opt.so(o) : Nat}

law opt_so_keeps_number:
  for o: E.Opts
  for v: Nat
  {E.opt.number(E.opts.set(o, E.ScrollOff{v})) == E.opt.number(o) : Bool}

law opt_so_keeps_relative:
  for o: E.Opts
  for v: Nat
  {E.opt.relative(E.opts.set(o, E.ScrollOff{v})) == E.opt.relative(o) : Bool}

law opt_so_keeps_indent:
  for o: E.Opts
  for v: Nat
  {E.opt.indent(E.opts.set(o, E.ScrollOff{v})) == E.opt.indent(o) : Bool}

law opt_so_keeps_shift:
  for o: E.Opts
  for v: Nat
  {E.opt.shift(E.opts.set(o, E.ScrollOff{v})) == E.opt.shift(o) : Nat}

law opt_so_keeps_hls:
  for o: E.Opts
  for v: Nat
  {E.opt.hls(E.opts.set(o, E.ScrollOff{v})) == E.opt.hls(o) : Bool}

law opt_so_keeps_ic:
  for o: E.Opts
  for v: Nat
  {E.opt.ic(E.opts.set(o, E.ScrollOff{v})) == E.opt.ic(o) : Bool}

law opt_so_keeps_scs:
  for o: E.Opts
  for v: Nat
  {E.opt.scs(E.opts.set(o, E.ScrollOff{v})) == E.opt.scs(o) : Bool}

law opt_so_keeps_ws:
  for o: E.Opts
  for v: Nat
  {E.opt.ws(E.opts.set(o, E.ScrollOff{v})) == E.opt.ws(o) : Bool}

law opt_so_keeps_et:
  for o: E.Opts
  for v: Nat
  {E.opt.et(E.opts.set(o, E.ScrollOff{v})) == E.opt.et(o) : Bool}

law opt_so_keeps_tw:
  for o: E.Opts
  for v: Nat
  {E.opt.tw(E.opts.set(o, E.ScrollOff{v})) == E.opt.tw(o) : Nat}

law opt_so_keeps_inc:
  for o: E.Opts
  for v: Nat
  {E.opt.inc(E.opts.set(o, E.ScrollOff{v})) == E.opt.inc(o) : Bool}

law preview_keeps_text:
  for e: E.Ed
  for found: Bool
  for u: Nat
  for d: Nat
  for c: Nat
  {B.text(E.buf(E.inc.hit(e, B.Hit{found, u, d, c}))) == B.text(E.buf(e)) : String}

law preview_miss:
  for e: E.Ed
  for u: Nat
  for d: Nat
  for c: Nat
  {E.inc.hit(e, B.Hit{False{}, u, d, c}) == e : E.Ed}

law preview_empty:
  for e: E.Ed
  for back: Bool
  {E.inc.show(e, "", back) == E.set_ipat(e, "") : E.Ed}

law preview_off:
  for e: E.Ed
  for back: Bool
  {E.inc.after(e, E.Search{back}, False{}) == e : E.Ed}

law preview_closed:
  for e: E.Ed
  for on: Bool
  {E.inc.after(e, E.Normal{}, on) == E.set_ipat(e, "") : E.Ed}

law preview_home_none:
  for e: E.Ed
  {E.inc.home(e, False{}) == e : E.Ed}

law not_searching:
  {E.is_searching(E.Normal{}) == False{} : Bool}

law scroll_off_zero:
  for top: Nat
  for pos: Nat
  for h: Nat
  {W.scroll.off(top, pos, h, 0n, 0n) == W.scroll(top, pos, h) : Nat}

law scroll_off_low:
  for +top: Nat
  for +pos: Nat
  for +k: Nat
  for +above: Nat
  for +below: Nat
  for e: {Nat.is_le(below, k) == True{} : Bool}
  {Nat.is_le(W.scroll.off(top, pos, 1n+k, above, below), pos) == True{} : Bool}

law scroll_off_high:
  for +top: Nat
  for +pos: Nat
  for +k: Nat
  for +above: Nat
  for +below: Nat
  {Nat.is_le(Nat.sub(pos, W.scroll.off(top, pos, 1n+k, above, below)), k) == True{} : Bool}

law so_wrong:
  {E.off.act(None{}) == E.Msg{"scrolloff needs a number: so=3"} : E.Act}

4.29Columns on the screen

A tab goes to the next tab stop, and a wide character is two columns.

law opt_set_ts:
  for o: E.Opts
  for v: Nat
  {E.opt.ts(E.opts.set(o, E.TabStop{v})) == v : Nat}

law opt_number_keeps_ts:
  for o: E.Opts
  for v: Bool
  {E.opt.ts(E.opts.set(o, E.Number{v})) == E.opt.ts(o) : Nat}

law opt_relative_keeps_ts:
  for o: E.Opts
  for v: Bool
  {E.opt.ts(E.opts.set(o, E.Relative{v})) == E.opt.ts(o) : Nat}

law opt_indent_keeps_ts:
  for o: E.Opts
  for v: Bool
  {E.opt.ts(E.opts.set(o, E.AutoIndent{v})) == E.opt.ts(o) : Nat}

law opt_shift_keeps_ts:
  for o: E.Opts
  for v: Nat
  {E.opt.ts(E.opts.set(o, E.Shift{v})) == E.opt.ts(o) : Nat}

law opt_hls_keeps_ts:
  for o: E.Opts
  for v: Bool
  {E.opt.ts(E.opts.set(o, E.HlSearch{v})) == E.opt.ts(o) : Nat}

law opt_ic_keeps_ts:
  for o: E.Opts
  for v: Bool
  {E.opt.ts(E.opts.set(o, E.IgnoreCase{v})) == E.opt.ts(o) : Nat}

law opt_scs_keeps_ts:
  for o: E.Opts
  for v: Bool
  {E.opt.ts(E.opts.set(o, E.SmartCase{v})) == E.opt.ts(o) : Nat}

law opt_ws_keeps_ts:
  for o: E.Opts
  for v: Bool
  {E.opt.ts(E.opts.set(o, E.WrapScan{v})) == E.opt.ts(o) : Nat}

law opt_et_keeps_ts:
  for o: E.Opts
  for v: Bool
  {E.opt.ts(E.opts.set(o, E.ExpandTab{v})) == E.opt.ts(o) : Nat}

law opt_tw_keeps_ts:
  for o: E.Opts
  for v: Nat
  {E.opt.ts(E.opts.set(o, E.TextWidth{v})) == E.opt.ts(o) : Nat}

law opt_inc_keeps_ts:
  for o: E.Opts
  for v: Bool
  {E.opt.ts(E.opts.set(o, E.IncSearch{v})) == E.opt.ts(o) : Nat}

law opt_so_keeps_ts:
  for o: E.Opts
  for v: Nat
  {E.opt.ts(E.opts.set(o, E.ScrollOff{v})) == E.opt.ts(o) : Nat}

law opt_ts_keeps_number:
  for o: E.Opts
  for v: Nat
  {E.opt.number(E.opts.set(o, E.TabStop{v})) == E.opt.number(o) : Bool}

law opt_ts_keeps_relative:
  for o: E.Opts
  for v: Nat
  {E.opt.relative(E.opts.set(o, E.TabStop{v})) == E.opt.relative(o) : Bool}

law opt_ts_keeps_indent:
  for o: E.Opts
  for v: Nat
  {E.opt.indent(E.opts.set(o, E.TabStop{v})) == E.opt.indent(o) : Bool}

law opt_ts_keeps_shift:
  for o: E.Opts
  for v: Nat
  {E.opt.shift(E.opts.set(o, E.TabStop{v})) == E.opt.shift(o) : Nat}

law opt_ts_keeps_hls:
  for o: E.Opts
  for v: Nat
  {E.opt.hls(E.opts.set(o, E.TabStop{v})) == E.opt.hls(o) : Bool}

law opt_ts_keeps_ic:
  for o: E.Opts
  for v: Nat
  {E.opt.ic(E.opts.set(o, E.TabStop{v})) == E.opt.ic(o) : Bool}

law opt_ts_keeps_scs:
  for o: E.Opts
  for v: Nat
  {E.opt.scs(E.opts.set(o, E.TabStop{v})) == E.opt.scs(o) : Bool}

law opt_ts_keeps_ws:
  for o: E.Opts
  for v: Nat
  {E.opt.ws(E.opts.set(o, E.TabStop{v})) == E.opt.ws(o) : Bool}

law opt_ts_keeps_et:
  for o: E.Opts
  for v: Nat
  {E.opt.et(E.opts.set(o, E.TabStop{v})) == E.opt.et(o) : Bool}

law opt_ts_keeps_tw:
  for o: E.Opts
  for v: Nat
  {E.opt.tw(E.opts.set(o, E.TabStop{v})) == E.opt.tw(o) : Nat}

law opt_ts_keeps_inc:
  for o: E.Opts
  for v: Nat
  {E.opt.inc(E.opts.set(o, E.TabStop{v})) == E.opt.inc(o) : Bool}

law opt_ts_keeps_so:
  for o: E.Opts
  for v: Nat
  {E.opt.so(E.opts.set(o, E.TabStop{v})) == E.opt.so(o) : Nat}

law tab_w_low:
  for +ts: Nat
  for col: Nat
  {Nat.is_le(1n, B.tab.w(ts, col)) == True{} : Bool}

law tab_w_high:
  for +t: Nat
  for col: Nat
  {Nat.is_le(B.tab.w(1n+t, col), 1n+t) == True{} : Bool}

law tab_w_start:
  {B.tab.w(8n, 0n) == 8n : Nat}

law tab_w_middle:
  {B.tab.w(8n, 3n) == 5n : Nat}

law tab_w_last:
  {B.tab.w(8n, 7n) == 1n : Nat}

law tab_w_next:
  {B.tab.w(8n, 8n) == 8n : Nat}

law tab_w_four:
  {B.tab.w(4n, 5n) == 3n : Nat}

law kind_letter:
  {B.cell.kind(97n) == 0n : Nat}

law kind_tab:
  {B.cell.kind(9n) == 1n : Nat}

law kind_wide:
  {B.cell.kind(26085n) == 2n : Nat}

law cell_w_one:
  for ts: Nat
  for col: Nat
  {B.cell.w(0n, ts, col) == 1n : Nat}

law cell_w_wide:
  for ts: Nat
  for col: Nat
  {B.cell.w(2n, ts, col) == 2n : Nat}

law dcol_simple:
  for r: Nat
  for l: String
  for ts: Nat
  {B.dcol.if(True{}, r, l, ts) == r : Nat}

law scan_end:
  for n: Nat
  {B.scan("", n, True{}) == n : Nat}

law scan_stop:
  for c: Char
  for t: String
  for n: Nat
  {B.scan(SCon{c, t}, n, False{}) == 4294967295n : Nat}

law dcol_end:
  for col: Nat
  for ts: Nat
  {B.dcol.go("", col, ts) == col : Nat}

law simple_end:
  for k: Nat
  {B.simple("", k) == True{} : Bool}

law ts_wrong:
  {E.stop.act(None{}) == E.Msg{"tabstop needs a number: ts=4"} : E.Act}

4.30More than one buffer

One buffer is on the screen. The other buffers wait in a list, each one as a Bf. The history in a Bf holds correct buffers only (S.Good), so a buffer in the list cannot be broken: the type says so. A buffer that goes on the screen comes back from it the same.

law park_unpark:
  for e: E.Ed
  for b: E.Bf
  {E.park(E.unpark(e, b)) == b : E.Bf}

law unpark_buf:
  for e: E.Ed
  for b: E.Bf
  {E.buf(E.unpark(e, b)) == E.bf.buf(b) : B.Buf}

law unpark_keeps_reg:
  for e: E.Ed
  for b: E.Bf
  {E.reg(E.unpark(e, b)) == E.reg(e) : String}

law unpark_keeps_regs:
  for e: E.Ed
  for b: E.Bf
  {E.regs(E.unpark(e, b)) == E.regs(e) : Map<&2, E.Reg>}

law unpark_keeps_opts:
  for e: E.Ed
  for b: E.Bf
  {E.opts(E.unpark(e, b)) == E.opts(e) : E.Opts}

law unpark_keeps_pat:
  for e: E.Ed
  for b: E.Bf
  {E.pat(E.unpark(e, b)) == E.pat(e) : String}

law unpark_keeps_maps:
  for e: E.Ed
  for b: E.Bf
  {E.maps(E.unpark(e, b)) == E.maps(e) : Map<&2, E.Act>}

law unpark_keeps_bufs:
  for e: E.Ed
  for b: E.Bf
  {E.bufs(E.unpark(e, b)) == E.bufs(e) : List<&2, E.Bf>}

law switch_same:
  for e: E.Ed
  for id: Nat
  {E.switch.if(e, id, True{}) == e : E.Ed}

law switch_none:
  for e: E.Ed
  for id: Nat
  {E.switch.to(e, None{}, id) == E.set_msg(e, "there is no buffer " ++ Nat.show(id)) : E.Ed}

law bfs_put_first:
  for b: E.Bf
  {E.bfs.put(Nil{}, b) == [b] : List<&2, E.Bf>}

law bfs_del_none:
  for id: Nat
  {E.bfs.del(Nil{}, id) == Nil{} : List<&2, E.Bf>}

law bfs_find_none:
  for id: Nat
  {E.bfs.find(Nil{}, id) == None{} : Maybe<&2, E.Bf>}

law bfs_clean_none:
  {E.bfs.dirty(Nil{}) == 0n : Nat}

law clean_not_dirty:
  for b: E.Bf
  for has: Bool
  for size: Nat
  {E.bf.dirty(E.bf.clean(b, has, size)) == False{} : Bool}

law clean_no_swap:
  for b: E.Bf
  for has: Bool
  for size: Nat
  {E.bf.swapped(E.bf.clean(b, has, size)) == False{} : Bool}

law clean_keeps_text:
  for b: E.Bf
  for has: Bool
  for size: Nat
  {E.bf.buf(E.bf.clean(b, has, size)) == E.bf.buf(b) : B.Buf}

law clean_keeps_id:
  for b: E.Bf
  for has: Bool
  for size: Nat
  {E.bf.id(E.bf.clean(b, has, size)) == E.bf.id(b) : Nat}

law quit_hidden_clean:
  for e: E.Ed
  {E.quit.hidden(e, 0n) == E.set_req(e, E.Leave{}) : E.Ed}

law quit_hidden_dirty:
  for e: E.Ed
  for p: Nat
  {E.quit.hidden(e, 1n+p) == E.set_msg(e, "no write since the last change in buffer " ++ Nat.show(1n+p) ++ " (:qa! discards it)") : E.Ed}

law quit_all_force:
  for e: E.Ed
  {E.quit.all(e, True{}) == E.set_req(e, E.Leave{}) : E.Ed}

law bd_refuses:
  for e: E.Ed
  {E.buf.del.cur(e, False{}, True{}) == E.set_msg(e, "no write since the last change (:bd! discards it)") : E.Ed}

law opened_in_place:
  for e: E.Ed
  {E.opened.place(e, True{}) == e : E.Ed}

law chain_idle:
  {E.chains(E.Idle{}) == False{} : Bool}

law chain_leave:
  {E.chains(E.Leave{}) == False{} : Bool}

law wall_no_stop:
  for e: E.Ed
  {E.wall.end(e, False{}) == e : E.Ed}

law wall_no_buffer:
  for e: E.Ed
  for id: Nat
  {E.wall.one(e, id, None{}) == e : E.Ed}

law ids_up_none:
  for cur: Nat
  {E.ids.up(Nil{}, cur) == 0n : Nat}

law nonzero_zero:
  for b: Nat
  {E.nonzero(0n, b) == b : Nat}

4.31More than one window

A layout says how the windows share the screen. The active window has its fields in the state, and each other window is a Win. One window takes all the area, and it has no line at its side.

law rects_one:
  for id: Nat
  for x: Nat
  for y: Nat
  for w: Nat
  for h: Nat
  {E.rects(E.LLeaf{id}, x, y, w, h) == [E.Rect{id, x, y, w, h}] : List<&2, E.Rect>}

law bars_one:
  for id: Nat
  for x: Nat
  for y: Nat
  for w: Nat
  for h: Nat
  {E.bars(E.LLeaf{id}, x, y, w, h) == Nil{} : List<&2, E.Rect>}

law rects_stacked:
  {E.rects(E.LSplit{False{}, E.LLeaf{2n}, E.LLeaf{1n}}, 0n, 0n, 60n, 11n) == [E.Rect{2n, 0n, 0n, 60n, 6n}, E.Rect{1n, 0n, 6n, 60n, 5n}] : List<&2, E.Rect>}

law rects_side:
  {E.rects(E.LSplit{True{}, E.LLeaf{2n}, E.LLeaf{1n}}, 0n, 0n, 60n, 11n) == [E.Rect{2n, 0n, 0n, 30n, 11n}, E.Rect{1n, 31n, 0n, 29n, 11n}] : List<&2, E.Rect>}

law bars_side:
  {E.bars(E.LSplit{True{}, E.LLeaf{2n}, E.LLeaf{1n}}, 0n, 0n, 60n, 11n) == [E.Rect{0n, 30n, 0n, 1n, 11n}] : List<&2, E.Rect>}

law split_close_new:
  for v: Bool
  {E.lay.del(E.lay.split(E.LLeaf{1n}, 1n, 2n, v), 2n) == E.LLeaf{1n} : E.Lay}

law split_close_old:
  for v: Bool
  {E.lay.del(E.lay.split(E.LLeaf{1n}, 1n, 2n, v), 1n) == E.LLeaf{2n} : E.Lay}

law last_window_stays:
  for k: Nat
  for id: Nat
  {E.lay.del(E.LLeaf{k}, id) == E.LLeaf{k} : E.Lay}

law split_order:
  for v: Bool
  {E.lay.ids(E.lay.split(E.LLeaf{1n}, 1n, 2n, v)) == [2n, 1n] : List<&2, Nat>}

law place_rect:
  for wid: Nat
  for wnext: Nat
  for wins: List<&2, E.Win>
  for lay: E.Lay
  for wx: Nat
  for wy: Nat
  for x: Nat
  for y: Nat
  for box: List<&2, E.Ws>
  {E.ws.place(E.Ws{wid, wnext, wins, lay, wx, wy, box}, x, y) == E.Ws{wid, wnext, wins, lay, x, y, box} : E.Ws}

law win_to_same:
  for e: E.Ed
  for id: Nat
  {E.win.to.if(e, id, True{}) == e : E.Ed}

law win_go_none:
  for e: E.Ed
  for id: Nat
  {E.win.go(e, None{}, id) == e : E.Ed}

law split_no_room:
  for e: E.Ed
  for vert: Bool
  {E.win.split.do(e, vert, False{}) == E.set_msg(e, "there is no room for a new window") : E.Ed}

law quit_one_window:
  for e: E.Ed
  for force: Bool
  for dirty: Bool
  {E.quit.win(e, force, dirty, True{}) == E.quit.app(e, force, dirty) : E.Ed}

law quit_closes_window:
  for e: E.Ed
  for force: Bool
  for dirty: Bool
  {E.quit.win(e, force, dirty, False{}) == E.win.close(e) : E.Ed}

law wins_del_none:
  for id: Nat
  {E.wins.del(Nil{}, id) == Nil{} : List<&2, E.Win>}

law wins_find_none:
  for id: Nat
  {E.wins.find(Nil{}, id) == None{} : Maybe<&2, E.Win>}

law after_end:
  for cur: Nat
  for found: Bool
  for first: Nat
  {E.ids.after(Nil{}, cur, found, first) == first : Nat}

law resize_same:
  for e: E.Ed
  for r: Nat
  for c: Nat
  {E.resize.if(e, r, c, True{}) == E.fit(e) : E.Ed}

4.32Syntax color

A lexer gives each character of a line an attribute, and the view shows an attribute as a color (src/syn.bend). The two parts of a text at a position make the text again.

law take_drop:
  for n: Nat
  for s: String
  {String.append(Y.take(n, s), Y.drop(n, s)) == s : String}

law plain_chars:
  for s: String
  {Y.chars(Y.ac.plain(s)) == s : String}

law take_chars:
  for n: Nat
  for s: String
  for a: Nat
  for acs: List<&2, Y.AC>
  {Y.chars(Y.ac.take(n, s, a, acs)) == String.append(Y.take(n, s), Y.chars(acs)) : String}

law lex_keeps_text:
  for fuel: Nat
  for +s: String
  for +st: Y.St
  for +lang: Y.Lang
  for +first: Bool
  {Y.chars(Y.lexed.acs(Y.lex.go(fuel, s, st, lang, first))) == s : String}

law eol_string:
  for q: Char
  {Y.st.eol(Y.Str{q}) == Y.Code{} : Y.St}

law eol_code:
  {Y.st.eol(Y.Code{}) == Y.Code{} : Y.St}

law eol_block:
  {Y.st.eol(Y.Block{}) == Y.Block{} : Y.St}

law eol_tri:
  for d: String
  {Y.st.eol(Y.Tri{d}) == Y.Tri{d} : Y.St}

law states_none:
  for st: Y.St
  for lang: Y.Lang
  {Y.states.go(Nil{}, st, lang) == st : Y.St}

law string_escape:
  for close: Bool
  for q: Char
  {Y.tok.str.c(True{}, close, q) == Y.Tok{2n, 4n, Y.Str{q}} : Y.Tok}

law string_close:
  for q: Char
  {Y.tok.str.c(False{}, True{}, q) == Y.Tok{1n, 4n, Y.Code{}} : Y.Tok}

law block_close:
  for n: Nat
  {Y.tok.block(True{}, n) == Y.Tok{n, 3n, Y.Code{}} : Y.Tok}

law block_goes_on:
  for n: Nat
  {Y.tok.block(False{}, n) == Y.Tok{1n, 3n, Y.Block{}} : Y.Tok}

law lex_python:
  {Y.attrs(Y.lexed.acs(Y.lex("x = 12 # c", Y.Code{}, Y.python()))) == [0n, 0n, 0n, 0n, 5n, 5n, 0n, 3n, 3n, 3n] : List<&2, Nat>}

law lex_bend:
  {Y.attrs(Y.lexed.acs(Y.lex("def f: Nat", Y.Code{}, Y.bend()))) == [6n, 6n, 6n, 0n, 0n, 0n, 0n, 7n, 7n, 7n] : List<&2, Nat>}

law lex_c_open:
  {Y.lexed.st(Y.lex("a /* b", Y.Code{}, Y.c())) == Y.Block{} : Y.St}

law lex_c_close:
  {Y.lexed.st(Y.lex("b */ c", Y.Block{}, Y.c())) == Y.Code{} : Y.St}

law lang_python:
  {Y.lang.id("a/b.py") == 2n : Nat}

law lang_text:
  {Y.lang.id("notes.txt") == 0n : Nat}

law lang_none_off:
  {Y.lang.on(Y.none()) == False{} : Bool}

law named_keeps_text:
  for e: E.Ed
  for path: String
  {E.buf(E.named(e, path)) == E.buf(e) : B.Buf}

law opt_set_syn:
  for o: E.Opts
  for v: Bool
  {E.opt.syn(E.opts.set(o, E.Syntax{v})) == v : Bool}

law opt_number_keeps_syn:
  for o: E.Opts
  for v: Bool
  {E.opt.syn(E.opts.set(o, E.Number{v})) == E.opt.syn(o) : Bool}

law opt_relative_keeps_syn:
  for o: E.Opts
  for v: Bool
  {E.opt.syn(E.opts.set(o, E.Relative{v})) == E.opt.syn(o) : Bool}

law opt_indent_keeps_syn:
  for o: E.Opts
  for v: Bool
  {E.opt.syn(E.opts.set(o, E.AutoIndent{v})) == E.opt.syn(o) : Bool}

law opt_shift_keeps_syn:
  for o: E.Opts
  for v: Nat
  {E.opt.syn(E.opts.set(o, E.Shift{v})) == E.opt.syn(o) : Bool}

law opt_hls_keeps_syn:
  for o: E.Opts
  for v: Bool
  {E.opt.syn(E.opts.set(o, E.HlSearch{v})) == E.opt.syn(o) : Bool}

law opt_ic_keeps_syn:
  for o: E.Opts
  for v: Bool
  {E.opt.syn(E.opts.set(o, E.IgnoreCase{v})) == E.opt.syn(o) : Bool}

law opt_scs_keeps_syn:
  for o: E.Opts
  for v: Bool
  {E.opt.syn(E.opts.set(o, E.SmartCase{v})) == E.opt.syn(o) : Bool}

law opt_ws_keeps_syn:
  for o: E.Opts
  for v: Bool
  {E.opt.syn(E.opts.set(o, E.WrapScan{v})) == E.opt.syn(o) : Bool}

law opt_et_keeps_syn:
  for o: E.Opts
  for v: Bool
  {E.opt.syn(E.opts.set(o, E.ExpandTab{v})) == E.opt.syn(o) : Bool}

law opt_tw_keeps_syn:
  for o: E.Opts
  for v: Nat
  {E.opt.syn(E.opts.set(o, E.TextWidth{v})) == E.opt.syn(o) : Bool}

law opt_inc_keeps_syn:
  for o: E.Opts
  for v: Bool
  {E.opt.syn(E.opts.set(o, E.IncSearch{v})) == E.opt.syn(o) : Bool}

law opt_so_keeps_syn:
  for o: E.Opts
  for v: Nat
  {E.opt.syn(E.opts.set(o, E.ScrollOff{v})) == E.opt.syn(o) : Bool}

law opt_ts_keeps_syn:
  for o: E.Opts
  for v: Nat
  {E.opt.syn(E.opts.set(o, E.TabStop{v})) == E.opt.syn(o) : Bool}

law opt_syn_keeps_number:
  for o: E.Opts
  for v: Bool
  {E.opt.number(E.opts.set(o, E.Syntax{v})) == E.opt.number(o) : Bool}

law opt_syn_keeps_relative:
  for o: E.Opts
  for v: Bool
  {E.opt.relative(E.opts.set(o, E.Syntax{v})) == E.opt.relative(o) : Bool}

law opt_syn_keeps_indent:
  for o: E.Opts
  for v: Bool
  {E.opt.indent(E.opts.set(o, E.Syntax{v})) == E.opt.indent(o) : Bool}

law opt_syn_keeps_shift:
  for o: E.Opts
  for v: Bool
  {E.opt.shift(E.opts.set(o, E.Syntax{v})) == E.opt.shift(o) : Nat}

law opt_syn_keeps_hls:
  for o: E.Opts
  for v: Bool
  {E.opt.hls(E.opts.set(o, E.Syntax{v})) == E.opt.hls(o) : Bool}

law opt_syn_keeps_ic:
  for o: E.Opts
  for v: Bool
  {E.opt.ic(E.opts.set(o, E.Syntax{v})) == E.opt.ic(o) : Bool}

law opt_syn_keeps_scs:
  for o: E.Opts
  for v: Bool
  {E.opt.scs(E.opts.set(o, E.Syntax{v})) == E.opt.scs(o) : Bool}

law opt_syn_keeps_ws:
  for o: E.Opts
  for v: Bool
  {E.opt.ws(E.opts.set(o, E.Syntax{v})) == E.opt.ws(o) : Bool}

law opt_syn_keeps_et:
  for o: E.Opts
  for v: Bool
  {E.opt.et(E.opts.set(o, E.Syntax{v})) == E.opt.et(o) : Bool}

law opt_syn_keeps_tw:
  for o: E.Opts
  for v: Bool
  {E.opt.tw(E.opts.set(o, E.Syntax{v})) == E.opt.tw(o) : Nat}

law opt_syn_keeps_inc:
  for o: E.Opts
  for v: Bool
  {E.opt.inc(E.opts.set(o, E.Syntax{v})) == E.opt.inc(o) : Bool}

law opt_syn_keeps_so:
  for o: E.Opts
  for v: Bool
  {E.opt.so(E.opts.set(o, E.Syntax{v})) == E.opt.so(o) : Nat}

law opt_syn_keeps_ts:
  for o: E.Opts
  for v: Bool
  {E.opt.ts(E.opts.set(o, E.Syntax{v})) == E.opt.ts(o) : Nat}

5.Design

The pure part has no effects, and all the laws are about it. The IO part is small.

terminal ─ characters ─► K.decode ─ keys ─► E.key ─ state ─► V.render ─► terminal
                                              │
                                              └─ request: write, read, leave ─► files
filework
src/buf.bendThe text as a zipper. An edit at the cursor costs O(1).
src/cmd.bendMotions and edits as data, and the functions that do them.
src/safe.bendBuffers with the proof that they are correct, and the operations on them.
src/hist.bendUndo and redo. A snapshot is one pointer.
src/win.bendThe scroll position that keeps the cursor on the screen.
src/key.bendChanges terminal characters into keys.
src/re.bendThe patterns of a search and of :s.
src/ed.bendThe state machine: modes, operators, bindings, the command line.
src/view.bendMakes one frame from the state.
src/app.bendThe IO shell: Edict.run is edict with a configuration.
config/example.bendAn example configuration.
src/file.bendReads and writes all the text of a file.
src/tty.bend .c .jsRaw mode, the size, the input, the exit. This is host code.
config.bendThe default configuration, and the base of your own.
main.bendedict with no configuration, for the tests and the benchmark.
bench/main.bendThe benchmark, with a pseudo-terminal effect in bench/pty.c.

The buffer is a zipper

The cursor divides the current line into two lists, and it divides the file into two lists of lines. Each list starts at the cursor. Thus an insertion is one new list cell.

type Buf is Data:
  Buf{
    l:  String,            # characters before the cursor, nearest first
    r:  String,            # characters after the cursor
    dn: List<String>,      # lines below the cursor, nearest first
    ab: List<String>,      # lines above the cursor, nearest first
    n:  Nat                # a cache: the number of lines in ab
  }

A request is data too

The pure editor cannot write a file. It puts a request in its state, and the shell does the request. Thus a test of the editor needs no terminal and no file. A shell command, a file for :r, the names for the tab key and the swap file are requests too. The pure editor decides if a write is safe (E.may.write), and laws say when it refuses.

6.Speed

The benchmark is a Bend program, bench/main.bend. The task edict:bench gets the newest release of Neovim and of Helix, runs the benchmark and writes bench/results.tsv. The numbers below come from that file.

Each editor runs in a pseudo-terminal of 50 rows, 160 columns and gets the same work as keys. The file has 100,000 lines, 5288890 bytes. The keys arrive as fast as the editor reads them. After an Escape key the terminal waits 30 ms, as a person does. Neovim is NVIM v0.12.6 and Helix is helix 25.07.1 (a05c151b): the newest releases when the benchmark ran. Each editor has its default configuration.

Time

The time is from the start of the editor to its end, so each time includes the time to open the file. Each value is the smallest time of the runs. The number above a bar compares that editor with edict.

start and stop

73.3 msedict
2.1x154.4 msNeovim
0.23x16.5 msHelix
edict is 2.1x faster than Neovim
Helix is 4.4x faster than edict

5,000 line moves, one key each

94.0 msedict
5.9x557.8 msNeovim
18x1738.6 msHelix
edict is 5.9x faster than Neovim
edict is 18x faster than Helix

type 5,000 characters, save

217.6 msedict
1.3x290.5 msNeovim
7.4x1603.0 msHelix
edict is 1.3x faster than Neovim
edict is 7.4x faster than Helix

delete 500 lines one at a time, save

149.2 msedict
1.5x228.6 msNeovim
1.7x259.3 msHelix
edict is 1.5x faster than Neovim
edict is 1.7x faster than Helix

delete 500 lines, undo all, stop

81.0 msedict
3.6x289.1 msNeovim
4.5x360.5 msHelix
edict is 3.6x faster than Neovim
edict is 4.5x faster than Helix

go to the end, add a line, save

280.0 msedict
0.63x176.6 msNeovim
0.32x88.5 msHelix
Neovim is 1.6x faster than edict
Helix is 3.2x faster than edict
time from start to end · lower is better

Memory

The memory is the largest resident memory of the editor during the work. Each value is the median of the runs.

start and stop

133.1 MBedict
0.16x21.8 MBNeovim
0.20x27.2 MBHelix
edict uses 6.1x more memory than Neovim
edict uses 4.9x more memory than Helix

5,000 line moves, one key each

133.2 MBedict
0.17x23.3 MBNeovim
0.21x27.4 MBHelix
edict uses 5.7x more memory than Neovim
edict uses 4.9x more memory than Helix

type 5,000 characters, save

134.1 MBedict
0.17x22.3 MBNeovim
0.21x27.8 MBHelix
edict uses 6.0x more memory than Neovim
edict uses 4.8x more memory than Helix

delete 500 lines one at a time, save

133.8 MBedict
0.18x23.8 MBNeovim
0.21x27.8 MBHelix
edict uses 5.6x more memory than Neovim
edict uses 4.8x more memory than Helix

delete 500 lines, undo all, stop

133.2 MBedict
0.18x24.3 MBNeovim
0.21x27.7 MBHelix
edict uses 5.5x more memory than Neovim
edict uses 4.8x more memory than Helix

go to the end, add a line, save

136.1 MBedict
0.16x22.0 MBNeovim
0.21x28.1 MBHelix
edict uses 6.2x more memory than Neovim
edict uses 4.8x more memory than Helix
peak memory · lower is better

The core of edict

These times are for the pure functions, with no terminal.

worktime for onecounttotal
load a file of 100,000 lines111.0 ms1111 ms
make the text of the file (save)108.0 ms1108 ms
insert a character11 ns2,000,00022 ms
move down one line46 ns2,000,00092 ms
go to the end and to the top21.1 ms20421 ms
a key, then a frame of 50 x 160187.3 µs20,0003747 ms
decode and do a typed character1.5 µs500,000760 ms
delete a line, and undo it5.6 µs100,000562 ms

What the numbers tell

One owner

Bend changes a value in place when the value has one owner. We measured two effects of this rule on 2026-11-19.

Memory and the layout of the text

We measured these three on 2026-11-19, with the file of 100,000 lines.

The cost of colors

A frame of 50 rows and 160 columns costs 0.19 ms with no colors and 0.78 ms with the colors of Python (2026-11-20). The lexer is one third of that, and most of its time is the read of the table of words for each word. The other part is the list of characters with their attributes that the view makes for each line. A text file has no lexer and pays nothing.

The size of the state

The state of the editor is a record, and Bend has no change in place for a record that has two owners. A read or a change of one field costs time in proportion to the size of the record. The state grew from 50 fields to 81, and a typed character went from 1.43 µs to 1.80 µs. We measured three layouts on 2026-11-20.

layouta typed characterdelete a line, undo it
All 81 fields in one record1.80 µs6.40 µs
Groups for all the fields that are related2.12 µs6.48 µs
The fields that keys use in the first record, the others in groups1.48 µs5.48 µs

A group is a record of its own, and the first record has one pointer to it. A field of a group costs two reads, so a group is good only for fields that the keys do not use: the command line, the file, the search, the marks. tools/fields.py makes the functions for the fields, so the code of the editor is the same for the two kinds.

Parallel calls

Bend can do two calls in parallel. This helps when each call has much work. It hurts when the work is small, because the call has a fixed cost. We measured each place before we made a decision. These measurements are from 2026-11-19, with keys sent through a pseudo-terminal.

placesequentialparalleldecision
All the text as one value: the text before and after the cursor81 to 87 ms66 to 73 msparallel (a save now writes blocks of lines, and does not use this)
One frame: the text and the status lines0.128 ms0.174 mssequential
Line motion: the two parts of the new line (5000j)0.6 ms81 mssequential

A parallel call does not change a proof. The checker sees the same two values.

7.Limits

edict is new. These parts of vim are not there at this time:

These parts are different from vim:

These limits are about edict as an editor: