Skip to content

mccode-clangformat: keep preprocessor lines intact - #3124

Merged
willend merged 1 commit into
mainfrom
clangformat-keep-pp-lines
Nov 16, 2026
Merged

willend merged 1 commit into
mainfrom
clangformat-keep-pp-lines

Conversation

@willend

@willend willend commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Free-form text area

Fixes #3123.

mccode-clangformat hid %/# lines from clang-format by turning them into // comments. clang-format wraps comments longer than ColumnLimit (160), so long one-line macros were split. In the Union dispatch macros this moved break; out of the macro (found in #3095).

The script now replaces each %/# line, plus its \ continuation lines, by a short placeholder comment. clang-format still sets the placeholder's indent, and the original text is put back unchanged. Continuation lines keep their indent relative to the directive, so they no longer move 2 columns right on every run.

Changing .clang-format instead (ReflowComments: false / IndentOnly) also fixed the macros, but reformatted many unrelated files.

Tests (clang-format 23.1.4, run over copies of all mcstas-comps and mcxtrace-comps .comp/.instr files):

  • Preprocessor lines, including continuations: no changes. The old script changed lines in IncoherentPhonon_process.comp and Inhomogenous_incoherent_process.comp.
  • First-run output vs the old script: differs only in those two Union files and in the continuation-line indent of 8 files with multi-line macros.
  • Running twice: a second run changes 2 files instead of 12. Elliptic_guide_gravity.comp (\-continued string literal) and Isotropic_Sqw.comp (MPI_MASTER( block) still change because they are not preprocessor lines. This PR leaves them as they are.

The script only runs on developer machines, and this PR changes no component code.


Declaration of use of AI-tools

  • Please add a checkmark here if you used AI-tools during the work for this contribution
  • Furter, please describe how / where and for what the tools were used: Claude Code (Claude Opus 5.5) found the cause, wrote the change and ran the repo-wide checks above. The change was reviewed by the author.

Development OS / boundary conditions

macOS (arm64), clang-format 23.1.4 from the conda mccode-dev environment. Not tested with older clang-format versions, Linux or Windows.


PR Checklist for contributing to McStas/McXtrace

  • My PR is meant to fix a specific, existing issue

  • My contribution contains something else

    • Explanation is added in free form text above or below the checklist

🤖 Generated with Claude Code

Replace %/# lines (and their continuation lines) by short placeholders
before running clang-format, so long macros are never reflowed or split.
Continuation lines keep their indent relative to the directive.

Fixes #3123

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@willend
willend merged commit 5b9c8ff into main Nov 16, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mccode-clangformat breaks long one-line #define macros

1 participant

⌂ Proxy