-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Break long function declarations into one parameter per line #1514
Comments
I would like to participate in the implementation of this feature @shimizukawa. Do you have any plans or known starting point for it? |
This is not an issue that he posted. This was migrated from bitbucket. The original author is Jørgen Ibsen.
BTW, this is related with writer modules. So I guess |
@tk0miya yes, I knew it was a imported issue, but I saw that was labeled by him several times. Thanks for the info about the related module, I have looked into it and I think it's possible to sketch something. But probably the best will be trying to expose a setting for configuring it, like a number of parameters in which start doing the line-breaking. |
It should be doable only by modifying individual domains. A domain is given a node to render a signature into. That node is a addnodes.desc_signature. Instead of directly adding child nodes to it, you can set |
@jakobandersen Nice info thanks, I'm going to start with that. Reading first how that was integrated in the C++ domain. |
I‘m facing the same issue in python. Is there any update? |
The missing(?) part in implementing this is how to do indentation. E.g., for a function \kw{def} \textbf{f}(a, b\\
\phantom{\kw{def} \textbf{f}(}c, d) This would make whitespace taking up the exact space needed. However, is something similar to this possible in HTML+CSS without too nasty haxes? and how with other output formats? |
Is there any progress on this issue? It would also be nice to use it with |
Are there any updates on this? It would be very useful for Python docs especially with the type annotations and default values. As keeping it on one line just makes it useless for the reader. @jakobandersen, having all the parameters on a new line (including the first one) should be simple, as it does not require calculating the indentation:
|
Thank you @tk0miya for the reference. Had to improve my CSS skills to achieve that :). So for anybody who is still searching, here is my /* Newlines (\a) and spaces (\20) before each parameter */
.sig-param::before {
content: "\a\20\20\20\20\20\20\20\20\20\20\20\20\20\20\20\20";
white-space: pre;
}
/* Newline after the last parameter (so the closing bracket is on a new line) */
dt em.sig-param:last-of-type::after {
content: "\a";
white-space: pre;
}
/* To have blue background of width of the block (instead of width of content) */
dl.class > dt:first-of-type {
display: block !important;
} If you are using readthedocs (which uses sphinx<2): /*Newlines (\a) and spaces (\20) before each parameter*/
dl.class em:not([class])::before {
content: "\a\20\20\20\20\20\20\20\20\20\20\20\20\20\20\20\20";
white-space: pre;
}
/*Newline after the last parameter (so the closing bracket is on a new line)*/
dl.class em:not([class]):last-of-type::after {
content: "\a";
white-space: pre;
}
/*To have blue background of width of the block (instead of width of content)*/
dl.class > dt:first-of-type {
display: block !important;
} Here it is in my project Class: Methods: I'm not very good at CSS, so suggestions are very welcomed! :) |
Cool :-) |
I think I found a scheme to solve this in HTML and somewhat in Latex. I'm not sure if there are other formats this is directly relevant for. Some observations, mostly applying to the dynamic nature of HTML, but I think the boxing in Latex can be derived from it:
The CSS in the example is based on using Flexbox, which can solve the vertical alignment by baseline issue as well as seemingly handle the wrapping in a nice way. These new box types will then become new classes in Any thoughts on this design idea? I started trying to implement some of this, but it diverged into extending the work started in #6417 to get closer to a solution to #4289. |
In LaTeX there is These things will not allow pagebreaks: even if we did not use With #8997 also So line wrapping inside signatures can definitly be done in LaTeX with suitable mark-up. Already now inserting a |
Any updates on this? |
Same, would be useful for multiline C functions. |
As a workaround, how can you just set to "ignore For example, changing class some.crazy.long.Name(lots, of, # | <- line end
parameters, # | <- line end
right, here) # | <- line end to class some.crazy.long.Name(lots, of, # | <- line end
parameters, right, here) # | <- line end or maybe even class some.crazy.long.Name(lots, of, # | <- line end
parameters, right, here) # | <- line end ? Either that or remove class Name(lots, of, parameters, right, # | <- line end
here) (Using Sphinx=4.4 and Edit: The last option is the easiest. Set |
@tk0miya - I see #5868 is locked as resolved, but this issue is still open. I have this function definition which is an example of one that has become particularly hard to read after adding type annotations: |
FWIW, I use the following as a workaround to keep function signatures legible. As a bonus, it forces me to clearly describe each argument to a function. # Automatically extract typehints when specified and place them in
# descriptions of the relevant function/method.
autodoc_typehints = "description"
# Don't show class signature with the class' name.
autodoc_class_signature = "separated" |
Unfortunately this doesn't help my case much, especially as this particular function has a pragmatic API that isn't well documented by covering every single parameter in that style. I guess we need to wait to hear from @tk0miya about where Sphinx is on this... |
Building on @kuzmoyev's solution, in order to make the newlines optional, I have the following /*Newlines (\a) and spaces (\20) before each parameter*/
.long-sig .sig-param:not(.short-sig .sig-param)::before {
content: "\a\20\20\20\20";
white-space: pre;
}
/* Newline after the last parameter (so the closing bracket is on a new line) */
.long-sig .sig-param:not(.short-sig .sig-param):last-of-type::after {
content: "\a";
white-space: pre;
} And I can thus optionally enable / disable this behaviour, using the Module
======
.. container:: long-sig
.. autoclass:: MyClass
.. automethod:: method_with_many_args
.. container:: short-sig
.. automethod:: method_with_few_args Then This cannot get @shimizukawa's expected result though, as one would need to adapt the added spacing to the length of the function name to get it. And well that's just hacky, a builtin solution from sphinx to automatically do this when you exceed N characters or arguments would be ideal. |
@kuzmoyev, thanks for a workaround (#1514 (comment)). |
Interestingly, the Sphinx Immaterial theme already does this. That theme extends It's only 76 lines of code to implement this commonly requested functionality. This only applies to Until then, long live the infamous CSS hack by @kuzmoyev. |
Gah! That's fantastic. I am, as always, profoundly ignorant of everything not @beartype (i.e., basically everything). Thanks a heap for both that sanity check and the immense volunteerism you do here and elsewhere, @pradyunsg. May @TLouf go down in Sphinx history as the blessed saviour of readable APIs. |
Closing as it is now supported since 7.1. Thank you again TLouf for that huge work! |
C function declarations that have many (or long) parameters resulting in a line break are hard to read. Would it be possible to optionally break them with one parameter per line (like doxygen).
I.e. instead of
I would like something like
The text was updated successfully, but these errors were encountered: