Elisp conventions

From benthamite/dotfiles · View interactive version

Elisp conventions is an AI agent skill from the GitHub repository benthamite/dotfiles. Apply local coding and verification rules when modifying or testing Emacs Lisp, or when explicitly reviewing code against these conventions. Use for dotfiles extras, standalone Elpaca packages, and other .el files; not for non-Elisp work or read-only bug, security, or design reviews where these conv

How to use this skill

Skill file

Emacs Lisp conventions

Use this skill before changing a .el file and keep it active through

verification. For an explicit read-only conventions review, apply only the

relevant style rules; do not turn the review into an edit or live-Emacs task.

Apply these rules to the requested change, not as permission to restyle unrelated

code, alter public interfaces, or operate on the active session. Preserve user

edits and inspect unsaved buffers before changing a visited source file.

Use lint-elisp in addition when the user asks for compiler, checkdoc, or lint

diagnostics. Use document-elisp-package when an Org manual must be created or

refreshed.

Coding style

a comment that explains a long implementation.

without an empty line. Separate later paragraphs with one empty line.

including throwaway scripts loaded into a live Emacs. Emacs 31 warns each

time it loads a file without one.

it is removed. First cancel its timers with cancel-timer, and remove any

hooks, advice and add-function wrappers it added. Only then run

fmakunbound and makunbound on its symbols. To make the timers findable,

keep every timer the script starts in one variable. Otherwise a pending

timer fires later against unbound symbols and opens the debugger in Pablo's

Emacs (void-variable restore--current, 2026-11-19).

command (hooks, timers, sentinels) logs routine progress and success to

*Messages* only, with inhibit-message bound to t, and echoes only

failures and requests the user must act on, such as an approval prompt,

even when a desktop notification also shows them, since that notification

can be hidden. A command the user invoked may report its progress normally.

command: timers, sentinels, filters and hooks. url-retrieve, a blocking

open-network-stream and websocket-open resolve the host and negotiate TLS

synchronously, with no timeout. Use an async curl subprocess with

--max-time, as agent-usage-http-get does, and pass secrets on its stdin.

On macOS even :nowait connections resolve the host on the main thread.

Exception, only where the connection cannot leave Lisp (forge/ghub,

emacs-slack's websocket): probe the host first with

simple-extras-call-when-reachable or simple-extras-probe-url. This

narrows the freeze window but does not close it, so record each use in the

incident file's Open section. Background: emacs/freeze-incidents.org,

2026-10-25.

Choose the layout

Every edited .el file uses one of these paths:

  1. Dotfiles extra: production source under

~/repos/dotfiles/emacs/extras/. This is canonical source; the active

Elpaca dotfiles checkout is a committed mirror. Use dotfiles-context for

source routing.

  1. Standalone package: identify the owning package from its metadata and

project instructions. For an Elpaca-managed package, use dotfiles-context

and bin/elpaca-package-resolve to obtain the actual registry ID, canonical

source, repository, and evidence label; do not guess from profile-directory

names. Unmanaged packages use their own documented checks and loading path.

For an externally maintained package fix, also use dotfiles-context's

upstream contribution workflow, even if the user did not mention a PR.

  1. Non-package Elisp: configuration and support files such as

.dir-locals.el or lockfile.el use the owning project's checks. Location

outside an Elpaca root does not by itself make a package non-package code.

Do not force an Elpaca rebuild or package manual onto unrelated files.

Test-only files inside a package follow the package's batch and focused ERT

paths, but they do not need a rebuild, live package reload, or manual update

unless they also change production code or user documentation.

Verification workflow

  1. Edit the canonical source.
  2. Establish clean batch evidence for the changed code:

below. It must load the canonical extras source.

using the resolver's evidence .label (the checkout label), not a guessed

library name. The runner resolves the package ID internally. An unmanaged

package uses its documented clean batch/compile/test workflow; do not

register or install it just to satisfy this skill.

example ~/repos/.worktrees/<repo>/<name>), add --worktree DIR before

PACKAGE in batch-test.sh or elisp-ert, so the runner loads and

records that worktree's files rather than the checkout's.

the relevant assertion and required project checks as well.

check through elisp-check-evidence file:RELATIVE-PATH -- PROJECT-CHECK.

One run may name several file: labels; it covers each of them.

PROJECT-CHECK must be a tracked executable in that repository. Do not

substitute an unrelated package check.

label with a project check that proves the repository is valid without it.

  1. Run focused ERT when behavior needs it. Read

references/testing.md for command forms and

stale-compiled-code safeguards.

  1. Before any live Emacs check, read

references/live-verification.md.

standalone package or dotfiles extra. It waits for the package rebuild,

exercises the named live path, and records package/commit-bound evidence.

Confirm the helper supports this package before using it. An isolated

fixture does not establish that an existing live session has the change.

The helper removes only that package's safe Elpaca build, unloads the

feature, and requires a non-nil expression that verifies its absence.

This destructive mode is only for an authorized whole-package removal,

not a library/file rename within a surviving package.

session unless that workflow makes the operation safe.

~/repos/dotfiles/claude/bin/elpaca-rebuild-wait PACKAGE
~/repos/dotfiles/claude/bin/elisp-live-verify PACKAGE -- '(PACKAGE-CHECK)'
~/repos/dotfiles/claude/bin/batch-test.sh PACKAGE
~/repos/dotfiles/claude/bin/elisp-check-evidence file:RELATIVE-PATH [file:RELATIVE-PATH...] -- PROJECT-CHECK
~/repos/dotfiles/claude/bin/elisp-ert PACKAGE TEST-FILE [TEST-NAME]

Test evidence counts only when it identifies the repository, package, and

source revision or equivalent content identity that was tested. A generic

session marker or a clean test for another package is not evidence for the

current change. Live evidence must also identify the committed repository and

package and establish the intended runtime, profile, source checkout, and

successful rebuild token. A true return value is not sufficient unless the

expression directly checks the requested behavior. Treat any stale-load warning

as a failed verification.

These rules are enforced on content, not on command spelling, so pipes,

chained git add && git commit, git -C, and multi-line messages all work.

Each successful runner records which Elisp files, at which contents, it

covered. In agent sessions the global Git pre-commit hook

(claude/git-hooks) rejects a commit whose Elisp contents no run covered and

prints the runner command to use. The post-commit hook records a live check

as owed for a production package, and the Stop hook keeps the turn from

ending until elisp-live-verify covers that commit or a later one. Nothing

blocks other commands in between, so a bug the live check finds can be fixed,

tested, and committed normally.

Never use load-file, eval-buffer, eval-defun, or manual

byte-compile-file to reload edited package code. Use the bounded rebuild helper

and the layout-specific sequence above.

Documentation and commit gates

Update and stage the matching manual for changed documented behavior:

manual. Use root README.md only when the project has no Org manual.

The current commit guard mechanically requires a selected manual for non-exempt

production .el changes when it finds a manual; it does not determine whether

behavior changed or whether that manual belongs to the package. Standard skill

scripts/*.el helpers instead require changed, selected SKILL.md or

references/*.md from each owning skill. Mixed package changes retain the

independent manual requirement.

Check the actual scoped commit paths. Never stage an unrelated manual or invent

a documentation change to appease the guard. If a truthful no-doc change is

blocked, diagnose the policy conflict; do not silently disable the guard.

When generated Texinfo/Info outputs change, validate and stage the destinations

actually declared by the manual, which need not share a basename.

Read declarations from the proposed commit's manual bytes, not unrelated

unstaged headers. For combined staging/commit syntax the guard cannot resolve,

stage the intended files separately and rerun the check without borrowing other

staged changes.

Manual updates are not required only because a commit changes a test file or a

generated/machine-owned file such as lockfile.el, *-autoloads.el, or

*-pkg.el, nor for a change that only replaces the contents of string literals

(a job title in a signature, say) when no manual quotes the replaced text; the

guard checks both. Read references/testing.md before

using the branch-local documentation deferral for a deliberate multi-commit

refactor or for a branch carrying a fix meant for another author's package.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.