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

Enhancement request: option to specify whether # is followed by space #1014

Closed
edreamleo opened this issue Sep 11, 2019 · 4 comments
Closed
Labels
F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs.

Comments

@edreamleo
Copy link

I am the author of Leo. At present, black inserts a blank between "#" and "@". Alas, this seriously interferes with Leo's 20-year-old format for sentinel comments.

This post discusses all the gory details. The take-away is that Leo has is no good solution to the problem.

Happily, there is a dead easy patch: In make_comment, change:

if content and content[0] not in " !:#'%":
    content = " " + content

to:

if content and content[0] not in " @!:#'%": # EKR: This string would better be an option.
    content = " " + content

Better, the option could be a regex, specifying the exact exceptions.

I hope you will consider adding such an option. Even a non-regex option would make a big difference.

Edward

P.S. For Leo, the regex would be the union of the following :-)

ref = g.angleBrackets(r'(.*)') # Yields << \1 >>, which is special Leo syntax.
delim1, delim2 = '#', ''
patterns = (
    # These patterns must be mutually exclusive.
    fr'^\s*{delim1}@afterref{delim2}$',             # @afterref
    fr'^(\s*){delim1}@(\+|-)all\b(.*){delim2}$',    # @all
    fr'^\s*{delim1}@@c(ode)?{delim2}$',             # @c and @code
    fr'^\s*{delim1}@comment(.*){delim2}',           # @comment
    fr'^\s*{delim1}@delims(.*){delim2}',            # @delims
    fr'^\s*{delim1}@\+(at|doc)?(\s.*?)?{delim2}\n', # @doc or @
    fr'^\s*{delim1}@end_raw\s*{delim2}',            # @end_raw
    fr'^\s*{delim1}@@first{delim2}$',               # @first
    fr'^\s*{delim1}@@last{delim2}$',                # @last
    fr'^(\s*){delim1}@\+node:([^:]+): \*(\d+)?(\*?) (.*){delim2}$', # @node
    fr'^(\s*){delim1}@(\+|-)others\b(.*){delim2}$', # @others
    fr'^\s*{delim1}@raw(.*){delim2}',               # @raw
    fr'^(\s*){delim1}@(\+|-){ref}\s*{delim2}$'      # section ref
)

EKR

@JelleZijlstra
Copy link
Collaborator

Related: #960

@edreamleo
Copy link
Author

@JelleZijlstra Thanks for the link. Imo, black should have more options. More people will use black if they can configure it so it works for them, their team, their organization.

@JelleZijlstra JelleZijlstra added the F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs. label May 30, 2021
@JelleZijlstra
Copy link
Collaborator

Let's take a decision in #3668.

@JelleZijlstra JelleZijlstra closed this as not planned Won't fix, can't repro, duplicate, stale Apr 29, 2023
@edreamleo
Copy link
Author

edreamleo commented Apr 29, 2023

@JelleZijlstra I agree that none of the options discussed in #3668 are perfect. Most projects should be able to find a way of living with Black's formatting of comments. For example:

  • Leo has long been able to read blackened sentinel comments.
  • Leo's newish --black-sentinels command-line option causes Leo to write black-compatible sentinel comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs.
Projects
None yet
Development

No branches or pull requests

2 participants