From aa1661781d31c842aab70570d77e8247b9e575d9 Mon Sep 17 00:00:00 2001 From: hemanth Date: Sun, 19 Jul 2026 15:28:44 -0700 Subject: [PATCH] repl: add auto-indentation for multiline input Automatically insert 2-space indentation on continuation lines based on brace/bracket/paren depth when entering multiline input. Refs: https://github.com/nodejs/node/issues/48164 Signed-off-by: hemanth --- doc/api/repl.md | 15 +- lib/internal/repl/utils.js | 52 ++++++ lib/repl.js | 8 + test/parallel/test-repl-auto-indent.js | 249 +++++++++++++++++++++++++ 4 files changed, 323 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-repl-auto-indent.js diff --git a/doc/api/repl.md b/doc/api/repl.md index c384ebf1391303..29108ee4c58964 100644 --- a/doc/api/repl.md +++ b/doc/api/repl.md @@ -27,7 +27,8 @@ result. Input and output may be from `stdin` and `stdout`, respectively, or may be connected to any Node.js [stream][]. Instances of [`repl.REPLServer`][] support automatic completion of inputs, -completion preview, simplistic Emacs-style line editing, multi-line inputs, +completion preview, automatic indentation, simplistic Emacs-style line editing, +multi-line inputs, [ZSH][]-like reverse-i-search, [ZSH][]-like substring-based history search, ANSI-styled output, saving and restoring current REPL session state, error recovery, and customizable evaluation functions. Terminals that do not support @@ -232,6 +233,18 @@ undefined undefined ``` +### Auto-indentation + + + +When entering +multi-line input (e.g., a function body or an object literal), the REPL +automatically indents continuation lines based on the current nesting +depth of braces (`{}`), brackets (`[]`), and parentheses (`()`). The REPL +uses 2-space indentation following the Node.js coding convention. + ### Reverse-i-search