isabelle-block
Mechanical edits to regions of Isabelle theory files, where a region is named by a line span or by the name of a lemma.
block move Foo.thy:helper_lemma before first_user # hoist a helper
block delete Foo.thy:dead_lemma
block move Foo.thy:1669..2657 before Bar.thy:46 # between theories
block reargs 'cost $1 $2' 'Suc (len $1)' Foo.thy --expect 14
Name addressing is the reason to use it. Foo.thy:helper_lemma resolves,
through isabelle-query's parser,
to the lemma's span, from its doc block through the last line of its proof.
So an edit needs no line arithmetic, and it cannot go stale between looking
a lemma up and editing it.
Install
python3 -m pip install isabelle-block
This puts block on your PATH. Needs Python 3.9 or later; depends on
isabelle-query and isabelle-layout, which pip fetches from PyPI. It
needs no Isabelle process.
Verbs
| verb | does |
|---|---|
move SRC:REGION before DEST |
relocate a block, within a file or between files |
copy SRC:REGION before DEST |
place a copy and keep the source |
delete FILE:REGION |
excise a block |
emit FILE:REGION |
print a block verbatim |
replace FILE:REGION NEWFILE |
swap a block for a file's contents |
sub OLD NEW FILE[:REGION]... |
literal substring substitution; OLD may span lines, and either side may be @FILE |
resub PAT NEW FILE[:REGION]... |
regex substitution; a match may span lines |
reargs 'F $1 $2' TMPL FILE[:REGION]... |
rewrite F's applications by their (bracket-aware) arguments; skips prose |
split SRC 'NAME|IMPORTS|RANGES'... [--cut] |
cut a theory into several |
merge BASE.thy SRC.thy... |
splice theory bodies into one |
A REGION is A..B (or A-B), a single line N, an entry NAME, or
all, which is also what a bare FILE means. A DEST is LINE, NAME,
FILE:LINE or FILE:NAME; the block lands immediately before it, preamble
included.
Modifiers:
--dry-runreports the edit and writes nothing.--expect Nmakessub,resubandreargsrefuse unless exactly N substitutions are made.--except NAMEleaves an entry out of every region.--no-preamblestarts a resolved span at the entry, not its doc block.--with-preamblekeeps the doc block even when it sits directly under a section heading. Such atextmay introduce the section rather than document the entry, and the source cannot say which. So there,delete,moveandreplacerefuse until you choose one of these two flags.--keep-heading/--with-heading: deleting the only entry under a heading refuses until you say whether the heading stays (bare) or the whole section goes with the entry.--land-above-text/--land-below-text: a block moved or copiedbefore NAME, landing under a heading, refuses when NAME's doc block sits directly under that heading, since the text may introduce the section. Say whether the block lands above the text or between it and NAME.--root DIRnames the session root whose keyword table name resolution uses. By default it is discovered asquerydiscovers it: an environment variable, a.isabelle-querymarker, or the nearestROOT. The table matters because a theory may use a command that another theory in its session declares.--no-trailing-blankcuts verbatim, without blank-line healing.
A refusal for want of a choice lists every open choice at once, so one rerun with a flag from each pair goes through.
A block moved before NAME that starts with its own heading, of the same or
higher rank as the heading above NAME, lands above that heading. So it
becomes a section beside NAME's, and does not swallow NAME.
block --help gives the full grammar, and block VERB --help gives one
verb's.
Every run ends with an explicit PASS: or FAIL: line, and the exit status
agrees. emit prints its PASS: on stderr, so block emit … > FILE is a
clean copy. A refusal writes nothing.
Related tools
Editing by line span and plain substitution are what ed, sed, sd and
fastmod already do. comby does bracket-aware
rewriting much as reargs does. block is worth installing if your edits
need what those tools cannot see:
- lemma names as addresses;
- the difference between Isar code and prose (
text, headings,\<comment>); - edits at theory level.
docs/related-tools.md compares them in detail.
Status
This is alpha, extracted from the NDTHT formalisation's bin/block.py, where it
did the project's mechanical theory surgery. The planned verbs (rename, a
caller-checked delete and an import-checked move) are in tasks.md.
Development
python3 -m venv .venv
.venv/bin/pip install -e '.[test]'
.venv/bin/pytest
Authors & license
By András Salamon, with Claude Opus 4.7, 4.8, 5, and 5.5. MIT.
Metadata
Release files for isabelle-block 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| isabelle_block-0.1.4.tar.gz | 31.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| isabelle_block-0.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 54.7 kB
Release files / isabelle_block-0.1.4.tar.gz
| Download URL | isabelle_block-0.1.4.tar.gz |
|---|---|
| Size | 31.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bbd5131d7290bdbd45209ca4ae1f786270841d653da07105df5d17a0cde44e70
|
|
BLAKE2b-256 checksum How to use checksums |
12595ff32ec3cb07e02bd15134f0dc4523fa5e0641ab9ba33ae6c7fb2840b14c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.9
|
Release files / isabelle_block-0.1.4-py3-none-any.whl
| Download URL | isabelle_block-0.1.4-py3-none-any.whl |
|---|---|
| Size | 22.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d8fb7366a14b56375324ff9884693e506cad004f6b7d8b53ebe3169a760ce66b
|
|
BLAKE2b-256 checksum How to use checksums |
4a11d819d916951b57e14effe814c75a8e647b058380c82f5548391d7b8ea27d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.9
|
Security for isabelle-block 0.1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.