Files
Nim/compiler
nimamasl114514 1e82deb73d fix #20078: nimpretty --indent applies to keepIndents regions (#25985)
## Summary
- nimpretty with non-default \--indent\ (e.g. 3 or 10) produced invalid
indentation in if/block/try expression regions because layouter kept the
original column when \keepIndents > 0\ and ignored \indWidth\.
- Rebase the column onto \indWidth\ using the relative offset from the
enclosing block baseline (\indentStack[^1]\).

## Root cause
\parser.nim\'s \
imprettyDontTouch\ template sets \keepIndents\ for if/block/try
expressions. layouter in the \keepIndents > 0\ branch used \ ok.indent\
(source column) directly as \indentLevel\ without scaling by \indWidth\,
so lines in these regions kept the original column and misaligned with
the rest of the file when \--indent\ differed from source indent width.

## Fix
\\\
im
em.indentLevel = em.indentStack.high * em.indWidth +
                 (tok.indent - em.indentStack[^1])
\\\

Keeps the relative offset from the enclosing block baseline but rebases
onto \indWidth\. At default \--indent:2\ the offset equals \indWidth\,
so output is unchanged (backwards compatible).

## Testing
- 12 custom cases x 3 indent values (2/3/10) = 36/36 pass
- nimpretty self-test suite 7/7 pass (no regression at default indent)
- 5 keepIndents scenarios (if/block/try expression continuation
alignment) that failed at indent:3/10 now pass

Fixes #20078.
2026-08-03 12:15:44 +02:00
..
2026-07-03 15:52:41 +02:00
2025-12-01 22:59:12 +01:00
2026-07-03 15:52:41 +02:00
2026-06-11 14:10:42 +02:00
2026-02-10 13:21:35 +01:00
2026-06-14 22:35:06 +02:00
2026-06-25 23:20:34 +02:00
2026-07-03 15:52:41 +02:00
2026-07-03 15:52:41 +02:00
2026-06-14 22:35:06 +02:00
2026-06-25 23:20:34 +02:00
2026-06-14 22:35:06 +02:00
2025-12-31 13:33:57 +01:00
2017-01-07 22:35:09 +01:00
2026-02-10 13:21:35 +01:00
2026-06-14 22:35:06 +02:00
2025-12-11 18:22:38 +01:00
2025-12-11 18:22:38 +01:00
2026-07-03 15:52:41 +02:00
2026-07-04 10:13:39 +02:00
2025-11-25 12:49:23 +01:00
2026-04-02 07:19:43 +02:00
2024-12-27 19:42:18 +01:00
2026-06-14 22:35:06 +02:00
2026-04-02 07:19:43 +02:00
2025-12-11 18:22:38 +01:00
2026-04-02 07:19:43 +02:00
2026-06-14 22:35:06 +02:00
2026-06-25 23:20:34 +02:00
2021-01-12 09:36:51 +01:00
2026-01-09 13:10:04 +01:00
2026-06-14 22:35:06 +02:00
2026-06-24 21:58:51 +02:00
2026-07-03 15:52:41 +02:00
2026-07-03 15:52:41 +02:00
2026-07-08 15:39:40 +02:00
2026-06-24 21:58:51 +02:00
2025-12-11 18:22:38 +01:00
2026-06-14 22:35:06 +02:00
2026-06-14 22:35:06 +02:00
2026-02-10 13:21:35 +01:00
2023-07-02 22:36:05 +02:00
2023-11-06 18:33:28 +01:00
2026-07-10 14:07:35 +02:00
2025-12-11 18:22:38 +01:00
2026-07-03 15:52:41 +02:00
2026-06-24 21:58:51 +02:00
2026-06-14 22:35:06 +02:00
2025-12-11 18:22:38 +01:00
2025-12-11 18:22:38 +01:00
2026-07-03 15:52:41 +02:00
2024-03-16 08:35:18 +08:00
2026-06-24 21:58:51 +02:00
2026-06-25 23:20:34 +02:00
2025-12-31 13:33:57 +01:00
2026-07-04 10:13:39 +02:00
2026-07-03 15:52:41 +02:00
2026-07-03 15:52:41 +02:00
2026-06-14 22:35:06 +02:00
2023-12-25 07:12:54 +01:00

Nim Compiler

  • This directory contains the Nim compiler written in Nim.
  • Note that this code has been translated from a bootstrapping version written in Pascal.
  • So the code is not a poster child of good Nim code.

See Internals of the Nim Compiler for more information.