Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to show macro's value #236

Open
amykyta3 opened this issue Mar 23, 2024 · 1 comment
Open

Option to show macro's value #236

amykyta3 opened this issue Mar 23, 2024 · 1 comment

Comments

@amykyta3
Copy link

Thanks for the great plugin!
Not sure if this is already supported or not, but it could be useful in some situations to also show the macro's value in the rendered documentation.

Something like:

.. c:automacro:: MY_MACRO
    :file: example.h
    :show_value: True

I'm in a situation where I need to document a cross-language API, and there are several constants defined in macros that would be useful to propagate to the docs. For now, I'm working around by duplicating the macro value in the docstring comment.

@jnikula
Copy link
Owner

jnikula commented Mar 24, 2024

Thanks for the feedback! I understand the use case, and I'll look into it, but there are a few downsides:

  • Basically all the directives translate to Sphinx C/C++ domain directives, and the c:macro directive doesn't have a way to provide the value. We'd have to somehow insert the value in the documentation.

  • I'm not super keen on adding a lot of new options. It's a balance, and I'm aiming for sane defaults. For example, the cpp:enumerator (and the C domain equivalent, though it's undocumented) support documenting the value. Hawkmoth does this automatically based on whether the source code has = <value> for the enumerator or not. See https://jnikula.github.io/hawkmoth/stable/examples.html#enum

  • If the macro values themselves contain macros, should they be recursively replaced? What about function-like macros? Could it be a sane default to document the value only if it's a "simple" number?

I'm not outright rejecting this, though, need to look into how it could be implemented. Using an enum might be a workaround in some cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants