nimamasl114514
db6d61b387
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 .
(cherry picked from commit 1e82deb73d )
2026-08-06 09:19:30 +02:00
..
2025-01-14 07:46:40 +01:00
2024-03-18 20:27:00 +01:00
2023-08-06 14:26:21 +02:00
2023-12-15 10:20:57 +01:00
2026-06-08 08:46:56 +02:00
2025-05-06 16:04:43 +02:00
2026-01-09 09:03:51 +01:00
2024-04-16 12:46:59 +02:00
2026-06-12 10:26:34 +02:00
2023-10-11 17:44:14 +02:00
2023-08-06 14:26:21 +02:00
2024-09-27 11:12:39 +02:00
2025-04-02 09:42:57 +02:00
2026-08-06 09:14:45 +02:00
2022-09-28 15:05:01 +02:00
2022-11-30 21:51:13 +01:00
2025-10-08 08:33:16 +02:00
2026-05-29 08:21:52 +02:00
2024-07-12 15:23:09 +02:00
2024-07-12 15:23:09 +02:00
2026-03-09 10:47:45 +01:00
2025-03-18 08:49:45 +01:00
2026-01-09 08:49:03 +01:00
2026-05-08 14:55:56 +02:00
2025-01-14 07:46:40 +01:00
2026-08-06 09:15:11 +02:00
2024-03-28 11:04:12 +01:00
2026-05-08 15:17:50 +02:00
2023-06-18 16:06:14 +02:00
2026-01-09 09:03:51 +01:00
2026-02-02 07:59:57 +01:00
2017-01-07 22:35:09 +01:00
2022-06-10 20:40:08 +02:00
2023-10-29 14:48:11 +01:00
2026-01-09 09:03:51 +01:00
2025-04-02 09:43:12 +02:00
2023-08-06 14:26:21 +02:00
2026-03-30 15:09:59 +02:00
2025-04-18 12:50:05 +02:00
2023-11-20 21:12:13 +01:00
2025-01-14 07:46:40 +01:00
2025-01-14 07:46:40 +01:00
2024-08-28 20:46:36 +02:00
2025-07-17 13:39:17 +02:00
2023-10-29 14:48:11 +01:00
2023-10-29 14:48:11 +01:00
2023-10-29 14:48:11 +01:00
2026-05-28 09:22:36 +02:00
2025-11-22 13:33:01 +01:00
2023-10-29 14:48:11 +01:00
2026-05-08 15:17:50 +02:00
2020-06-01 19:21:41 +02:00
2026-08-06 09:16:19 +02:00
2025-10-14 11:37:24 +02:00
2023-12-15 08:13:25 +01:00
2025-01-15 10:21:20 +01:00
2026-07-06 08:44:50 +02:00
2025-07-17 13:39:41 +02:00
2026-04-07 08:34:55 +02:00
2026-01-09 09:03:51 +01:00
2026-08-06 09:19:30 +02:00
2026-05-22 08:57:23 +02:00
2026-04-03 12:47:11 +02:00
2025-01-14 07:46:40 +01:00
2026-06-08 14:48:42 +02:00
2026-01-26 09:13:17 +01:00
2025-03-25 09:44:55 +01:00
2026-06-09 06:24:20 +02:00
2025-01-14 07:46:40 +01:00
2021-01-12 09:36:51 +01:00
2026-03-09 10:13:04 +01:00
2024-07-09 09:29:45 +02:00
2024-04-05 08:54:48 +02:00
2026-08-06 09:19:22 +02:00
2025-06-06 08:32:58 +02:00
2025-01-14 07:45:59 +01:00
2026-01-26 09:13:17 +01:00
2026-06-08 14:48:42 +02:00
2026-02-26 17:32:51 +01:00
2024-07-17 18:25:19 +02:00
2023-12-15 08:13:25 +01:00
2025-10-27 08:51:00 +01:00
2024-04-10 14:41:16 +02:00
2023-10-29 14:48:11 +01:00
2023-10-29 14:48:11 +01:00
2025-01-14 07:46:40 +01:00
2023-10-29 14:48:11 +01:00
2024-08-12 15:33:26 +02:00
2023-04-17 20:55:22 +02:00
2025-04-04 10:08:30 +02:00
2026-06-12 10:27:15 +02:00
2023-08-06 14:26:21 +02:00
2025-01-14 07:34:32 +01:00
2025-09-24 08:54:39 +02:00
2025-07-17 13:39:26 +02:00
2022-08-24 09:44:16 +02:00
2025-01-14 07:51:55 +01:00
2023-10-29 14:48:11 +01:00
2025-04-14 10:52:41 +02:00
2025-04-14 10:52:50 +02:00
2023-03-03 07:36:38 +01:00
2026-06-12 10:27:15 +02:00
2018-05-27 19:19:12 +02:00
2025-04-14 10:53:01 +02:00
2023-10-29 14:48:11 +01:00
2024-04-10 14:41:16 +02:00
2024-09-03 09:19:52 +02:00
2023-07-02 22:36:05 +02:00
2026-04-16 19:44:36 +02:00
2023-10-29 14:48:11 +01:00
2025-04-14 10:52:41 +02:00
2023-11-06 18:33:28 +01:00
2023-08-10 14:26:40 +02:00
2020-09-11 01:04:07 +02:00
2023-10-29 14:48:11 +01:00
2026-07-06 08:42:41 +02:00
2026-04-13 12:06:27 +02:00
2026-06-09 06:24:20 +02:00
2026-08-06 09:18:45 +02:00
2025-03-03 14:10:49 +01:00
2026-01-12 08:48:55 +01:00
2026-06-08 14:48:32 +02:00
2025-04-21 19:09:45 +02:00
2025-09-22 08:47:23 +02:00
2026-08-06 09:16:19 +02:00
2025-10-17 09:24:11 +02:00
2025-01-14 07:46:40 +01:00
2026-07-18 10:23:03 +02:00
2026-06-08 14:48:42 +02:00
2022-12-11 16:58:50 +01:00
2025-05-05 08:19:11 +02:00
2026-08-06 09:17:58 +02:00
2026-02-26 17:34:42 +01:00
2026-07-18 10:22:47 +02:00
2026-08-06 09:18:57 +02:00
2023-11-20 21:12:13 +01:00
2026-06-15 08:01:21 +02:00
2024-03-16 08:35:18 +08:00
2025-01-14 07:46:40 +01:00
2025-09-22 08:48:48 +02:00
2025-07-19 08:17:30 +02:00
2024-04-10 14:41:16 +02:00
2023-08-10 14:26:40 +02:00
2026-06-08 14:50:54 +02:00
2026-08-06 09:16:19 +02:00
2025-12-15 20:29:49 +01:00
2026-03-30 15:10:17 +02:00
2026-05-29 08:25:57 +02:00
2023-10-29 14:48:11 +01:00
2026-08-06 09:19:22 +02:00
2026-01-26 09:12:59 +01:00
2023-12-12 16:54:50 +01:00
2026-06-15 08:01:11 +02:00
2026-03-10 09:30:31 +01:00
2026-08-06 09:11:44 +02:00
2023-08-10 14:26:40 +02:00
2024-04-10 14:41:16 +02:00
2025-05-12 14:20:32 +02:00
2023-10-29 14:48:11 +01:00
2025-01-14 12:24:00 +01:00
2023-12-25 07:12:54 +01:00