trivial-toplevel-prompt

2026-11-29

Portability library to customize REPL prompts.

Upstream URL

codeberg.org/aartaka/trivial-toplevel-prompt

Author

Artyom Bologov

License

BSD-3 Clause
README
<title>Trivial Toplevel Prompt</title> <main> <h1>Trivial Toplevel Prompt</h1> <p> Trivial Toplevel Prompt is a petty portability library to set the implementation-specific REPL prompt to a new, possibly more useful, value. It allows showing the inspect/debug/stepping statuses alongside the command number, current package, and current process or thread. <p> Tested on (basically all the implementations I can run): <ul> <li> SBCL, <li> CCL, <li> ECL, <li> ABCL, <li> CLISP, <li> Allegro CL, <li> CMUCL (untested, incomplete), <li> Lem editor built-in REPL. </ul> <p> Help in supporting other implementations (like <a href=http://www.lispworks.com/documentation/lw80/lw/lw-lispworks-87.htm#lispworks_marker-line-3817>LispWorks with its *prompt*</a>) is much appreciated! <h2 id=getting-started>Getting Started</h2> <p> Clone the Git repository: <pre lang=sh> git clone https://codeberg.org/aartaka/trivial-toplevel-prompt ~/.local/share/common-lisp/source/ </pre> <p> And then load <code>"trivial-toplevel-prompt"</code> in the REPL: <pre lang=lisp> (asdf:load-system "trivial-toplevel-prompt") ;; or, if you use Quicklisp (ql:quickload "trivial-toplevel-prompt") </pre> <p> You can also install Trivial Toplevel Prompt via Guix, using the bundled <code>guix.scm</code> file: <pre lang=sh> guix package -f guix.scm </pre> <h2 id=api>API</h2> <p> The main API function is <code>set-toplevel-prompt</code>. The values that it accepts are: <dl> <dt> String <dd> use it as a format control. <dt> Function <dd> use it to print the prompt to the REPL stream. </dl> <p> Arguments provided to both the format control and the printing function are (mostly modeled after Allegro CL APIs): <ul> <li> Stream to print the prompt to. Only provided for the function, implied for the string. <li> The current process/thread name (a string) or NIL when not provided/meaningless. <li> The shortest possible name/nickname of the current package (<code>cl:*package*</code>). <li> A number indicating the command/expression number. <li> A number indicating the current break/debug level. <li> A boolean indicating whether stepping is enabled. <li> A boolean indicating whether <code>inspect</code> is in progress. </ul> <p> Note that some implementations have custom REPLs for stepping and inspection, so <code>set-toplevel-prompt</code> will be useless for inspect and stepping arguments. Then there's <code>reset-toplevel-prompt</code> to undo the effect of <code>set-toplevel-prompt</code>, basically restoring the previous prompt state. <h2 id=examples>Examples</h2> <p> Here's a simple format control example: just skip the process name, print package name and command number. <pre lang=lisp> (trivial-toplevel-prompt:set-toplevel-prompt "~*~a~@[(~d)~]: ") ;; CL-USER(7): </pre> <p> And a more involved, Allegro-style (<code>[4si] CL-USER(29):</code>) prompt: <pre lang=lisp> (trivial-toplevel-prompt:set-toplevel-prompt (lambda (stream process/thread-name package-name command-number debug-level stepping-p inspect-p) (declare (ignorable process/thread-name)) (when (or debug-level stepping-p inspect-p) (format stream "[~@[~d~]~@[s~*~]~@[i~*~]] " debug-level stepping-p inspect-p)) (format stream "~a~@[(~d)~]: " package-name command-number))) ;; [4si] CL-USER(29): </pre> <p> And here’s a <a href=https://en.wikipedia.org/wiki/Kaomoji>kaomoji</a> prompt so that you’re as excited about programming as this little fella: <pre lang=lisp> (trivial-toplevel-prompt:set-toplevel-prompt "(ノ´ヮ´)ノ*:・゚✧: ") </pre> <p> And then reset it: <pre lang=lisp> (trivial-toplevel-prompt::reset-toplevel-prompt) ;; CL-USER(7): (trivial-toplevel-prompt::reset-toplevel-prompt) ;; Back to implementation-specific prompt. </pre> <style> /* Light theme. */ :root { --bg: var(--light, papayawhip); --fg: var(--dark, black); --accent: var(--light-accent, maroon); --on-accent: var(--bg); --gray: var(--neutral, darkgray); } * { font-palette: ligth; } /* Dark theme. */ @media (prefers-color-scheme: dark) { :root { --bg: var(--dark, black); --fg: var(--light, papayawhip); --accent: var(--dark-accent, lightcoral); --on-accent: var(--bg, black); --gray: var(--neutral, lightgray); } * { font-palette: dark; } } /* Increased accessibility mode. */ @media (forced-colors: active) { --bg: Canvas; --fg: CanvasText; --accent: AccentColor; --on-accent: AccentColorText; } * { box-sizing: border-box; border-spacing: 0; scrollbar-color: var(--accent) rgba(0, 0, 0, 0); caret-color: var(--accent); accent-color: var(--accent); } ::selection, mark, ::target-text { background-color: var(--accent); color: var(--on-accent); border-radius: 0.2em; padding: 0 0.1em; } ::marker { color: var(--accent); } body { margin: 0; padding: 1em; background: var(--bg); color: var(--fg); min-height: 100%; font-size: max(1em, 16px, 1rem); } main { padding: 1em; } @media (min-device-width: 500px) { main { margin: 0 auto; max-width: 70em; } } a { color: inherit; font-family: inherit; font-style: italic; } a:hover { background-color: var(--accent); color: var(--on-accent); } dt { color: var(--accent); font-weight: bold; } .note { border-radius: 0.2em; border: 0.1em solid var(--accent); padding: 0 1em; margin: 1em 0; } pre { overflow-x: auto; } h1[id]::after, h2[id]::after, h3[id]::after, h4[id]::after, h5[id]::after, h6[id]::after { content: " (#" attr(id) ")"; color: var(--gray); } </style>

Dependencies (0)

    Dependents (0)

      • GitHub
      • Quicklisp