Colordiff renders colorful syntax-highlighted diffs in a terminal. It produces a semantic row model for application integration and can render that model directly with ANSI colors.
Colordiff compares complete before-and-after documents. It removes their common prefix and suffix, keeps one surrounding context line, and renders one bounded middle change block.
Colordiff depends on ColorLisp and cl-colorist. With the systems available to ASDF:
(asdf:load-system "colordiff")For development with Qlot:
./script/bootstrap
./script/check(let ((rows
(colordiff:render-diff
:removed-content "(defun answer () 41)"
:added-content "(defun answer () 42)"
:removed-start-line 10
:added-start-line 10
:source-path "answer.lisp")))
(colordiff:write-ansi rows))SOURCE-PATH is used only for language classification. Pass
:SYNTAX-HIGHLIGHT-P NIL to skip highlighting.
Every changed row carries a line number. An absent :REMOVED-START-LINE or
:ADDED-START-LINE inherits the other side’s coordinates, and when both are
absent the documents number from their own first line. :LINE-LIMIT bounds
each removed or added block independently.
RENDER-DIFF returns a list of rows. By default, each row is a list of SPAN
objects carrying a semantic role and display text. Roles distinguish:
- context
- removed and added gutters
- ordinary code
- elisions
- ColorLisp syntax categories
Diff boundaries are computed from the original logical lines before display sanitization, so control-only changes stay visible.
Applications with an existing styled-text model can supply :SPAN-FUNCTION.
The function receives a role keyword and text; its return values are placed
directly into the rows. :SANITIZE-LINE-FUNCTION lets an application apply
its own terminal-safety policy before highlighting and layout.
HIGHLIGHT-SPANS and HIGHLIGHT-LINES expose the same style-neutral ColorLisp
mapping for callers that need syntax rendering outside a diff.
WRITE-ANSI writes semantic rows to a stream. ANSI-STRING returns the same
presentation as a string. Both accept a Colorist color level and a replacement
style table. Passing :NONE as the color level produces plain text. The final
terminal boundary visibly escapes CSI, OSC, C0, C1, DEL, and embedded line
controls even for spans constructed directly or returned by the standalone
syntax helpers.
Copyright 2026 Lambda Symbolics OÜ
Licensed under COLL-Attribution. See LICENSE.lisp for the authoritative terms.