Skip to content

Example style guide, 80-column examples, tested doc fences - #19

Draft
tony wants to merge 18 commits into
masterfrom
example-style
Draft

tony wants to merge 18 commits into
masterfrom
example-style

Conversation

@tony

@tony tony commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor
  • StyLua formats examples/ at 80; the rest of the source keeps 100.
  • A stdlib Python check holds Markdown fences and comments to 80, which StyLua never reads or wraps.
  • A fence harness runs every lua fence in the README and docs (none ran).

Merge after libtmux/docs#101 deploys: it makes 80 columns fit a libtmux.org code block from 1024 px up.

What changed

Policy

  • .github/WRITING.md gains an ## Examples section after ## Markdown and code blocks (now with a ### Code blocks heading the shared text links to). The existing example-shape rules stay under ## Documentation and examples. The "In this repository" block names StyLua, stylua.toml, examples/stylua.toml, and the <!-- lua: ... --> fence classes.
  • AGENTS.md routes code examples to it.

Tooling

  • examples/stylua.toml is a copy of the root config with column_width = 80. StyLua starts in the directory of the file being formatted and searches upward, so the existing stylua --check needs no new flags. A [[formatter_copies]] entry fails the check if the copy differs from the root in anything but column_width.
  • scripts/check_example_width.py and .github/example-width.toml read every **/*.md page, examples/**/*.lua and examples/api/run.sh. Two [[exclude]] entries, each with a reason: examples/stylua.toml, which [[formatter_copies]] already compares, and examples/api/manifest.json, a machine-read index whose JSON strings cannot wrap. One [[allow]] entry: the deliberately wide Bad line in WRITING.md's port block. They run as the width gate inside scripts/check.py mid: self-test first, then the check.
  • scripts/check_doc_fences.py (the fences gate, outer phase): each lua fence carries <!-- lua: run | fragment | compile-only: reason --> and an unclassified fence fails. The 11 existing fences are 1 run, 7 fragments, 3 compile-only.
  • The fences gate runs in the outer phase, not mid, because it needs a tmux 3.7c binary.

Examples

  • One mechanical StyLua reformat of examples/**/*.lua (10 Lua files, +124/-45, plus the new examples/stylua.toml); the hand edits name session, query and split options before the call, and split two shell commands.

Evidence

  • StyLua 2.4.0 (the version ci.yml installs) takes the width from the nearest config (search order, column_width). column_width guides the formatter and does not cap a line, which is why the separate width check exists.
  • Rejected a root column_width of 80, which would reflow lua/ and packages/ for no reader benefit; Examples(style): Format examples at 80 columns weighs the other options.
  • StyLua needs two passes on a method chain inside a call argument in examples/quickstart.lua: the second pass rewrites the first pass's output with identical flags and config. Examples(style[quickstart]): Name session options hoists that chain into a local.
  • Run against origin/master, this branch's checker and config report 51 lines over 80 in 15 files, and the commits fix all of them.
  • Fence harness: each fence is classified and run; matching fences line for line against example programs was rejected because only 1 of 11 matched. A planted pane:capturee in docs/panes.md fails with "attempt to call a nil value (method 'capturee')"; the clean tree passes. The gate needs TMUX_BIN at the 3.7c toolchain the repository bootstraps, because libtmux-lua does not support tmux 3.7d yet.

How to verify

$ mise exec -- python scripts/check_example_width.py --self-test
$ mise exec -- python scripts/check.py width
$ mise exec -- python scripts/check.py format

The fence harness needs the repository's tmux 3.7c in TMUX_BIN.

$ mise exec -- python scripts/check.py fences

@tony
tony force-pushed the example-style branch 7 times, most recently from fe92448 to d332095 Compare October 4, 2026 16:50
@tony
tony deployed to docs-preview October 4, 2026 18:18 — with GitHub Actions Active
@tony
tony deployed to docs-preview October 4, 2026 20:40 — with GitHub Actions Active
@tony
tony deployed to docs-preview October 4, 2026 21:35 — with GitHub Actions Active
@tony
tony force-pushed the example-style branch 4 times, most recently from 7befbfe to 0b0dd91 Compare October 4, 2026 23:18
@tony
tony deployed to docs-preview October 4, 2026 23:51 — with GitHub Actions Active
@tony
tony deployed to docs-preview October 5, 2026 01:46 — with GitHub Actions Active
@tony
tony force-pushed the example-style branch 3 times, most recently from 25929a5 to e9a2b57 Compare October 5, 2026 05:56
@tony
tony deployed to docs-preview October 5, 2026 07:06 — with GitHub Actions Active
@tony
tony deployed to docs-preview October 5, 2026 10:50 — with GitHub Actions Active
@tony
tony deployed to docs-preview October 5, 2026 22:06 — with GitHub Actions Active
@tony
tony deployed to docs-preview October 5, 2026 22:28 — with GitHub Actions Active
@tony
tony force-pushed the example-style branch 2 times, most recently from 4b395a1 to 91252e7 Compare October 11, 2026 02:16
@tony
tony deployed to docs-preview October 11, 2026 02:44 — with GitHub Actions Active
@tony
tony deployed to docs-preview October 11, 2026 03:10 — with GitHub Actions Active
@tony
tony deployed to docs-preview October 11, 2026 03:48 — with GitHub Actions Active
@tony
tony force-pushed the example-style branch 8 times, most recently from ec0c318 to 0bc1ca9 Compare October 11, 2026 06:22
@tony
tony deployed to docs-preview October 11, 2026 06:57 — with GitHub Actions Active
@tony
tony deployed to docs-preview October 11, 2026 09:33 — with GitHub Actions Active
@tony
tony deployed to docs-preview October 11, 2026 09:52 — with GitHub Actions Active
@tony
tony deployed to docs-preview October 11, 2026 10:23 — with GitHub Actions Active
@tony
tony deployed to docs-preview October 11, 2026 10:49 — with GitHub Actions Active
@tony
tony deployed to docs-preview October 11, 2026 11:40 — with GitHub Actions Active
tony added 3 commits October 12, 2026 04:12
why: Example width and shape were unwritten, so each example was
formatted by whatever its tool did. The shared section states the rule;
the repository block names StyLua and the check.

what:
- Add `## Examples` after `## Markdown and code blocks`, byte-identical
  to the shared section in libtmux/docs#101
- Add a `### Code blocks` heading so the shared section's
  `#code-blocks` link resolves; this file's own heading is the longer
  `## Markdown and code blocks`
- Add `### In this repository`: the StyLua config and the width check,
  the surfaces StyLua skips, which examples run, and the copies that
  have no sync tool
- Show the README split line as Bad and its named-option form as Good
why: An agent adding an example has no reason to open WRITING.md, where
the width rule now lives.

what:
- Add "any code example (example programs, Markdown code blocks)" to the
  WRITING.md routing line and link its Examples section
why: Nothing stopped a README fence or an example from growing past 80
columns. StyLua treats `column_width` as a guide rather than a limit and
does not wrap comments, and it never sees Markdown, so a check has to
read both. A new file under examples/ would also go unread unless
something forces a decision about it. A libtmux.org code block holds 78
columns at 1024 px (Firefox, WebKit, CI's Chrome) and 99 at 1440 px
(Firefox, WebKit); libtmux/docs#101 sizes the code font so 80 columns
fit from 1024 px up.

what:
- Add scripts/check_example_width.py, the shared checker, and
  .github/example-width.toml naming the Markdown and example files
- Add the `width` gate to scripts/check.py: it runs the checker's
  --self-test, then the check, inside `mid`
- Document the command in CONTRIBUTING.md beside the other gates
- Check every `**/*.md` page with no exclusions, so WRITING.md and
  AGENTS.md, which CLAUDE.md links to, are held to the width too
- Check every Lua program under examples/ and the launcher
  examples/api/run.sh as `sources`, since a reader opens and copies them
- Require every tracked file under examples/ to be checked or excluded
  with a reason: exclude examples/api/manifest.json (a machine-read
  index whose JSON strings cannot wrap) and examples/stylua.toml
- Check that examples/stylua.toml equals stylua.toml except for
  `column_width`, through a `[[formatter_copies]]` entry
- Point a wide line at Reaching 80, and a wide console command at its
  shell's continuation
- Allow one line, with a reason: the Bad example in WRITING.md's port
  block, which shows the width problem the Good example fixes;
  allow_ceiling equals that one entry
- Record shared_digest, the --digest of WRITING.md's shared section, so
  a local edit to it fails the check
- Record checker_digest, the --digest of this checker, so a local edit
  to it fails until every port changes together

This branch was successfully deployed

1 active deployment
docs-preview — a286a0b2 Deployed Oct 12, 2026 by tony via publish (pr-19, pr, false, docs-preview, true) / publish #135
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant