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

Modify foldEndPattern in Atom settings #161

Merged
merged 1 commit into from
Sep 12, 2018

Conversation

kylebarron
Copy link
Contributor

(This is in conjunction with a similar PR sent to language-python atom/language-python#274, though the text is modified slightly for MagicPython)

Description of the Change

Add a value for foldEndPattern in the package settings. This improves the folding behavior for dictionaries, lists, and functions. It folds the entire logical syntax item instead of leaving the ending character on a separate line. It also improves the use of Hydrogen when the ending }, ), or ] is on a separate line and not indented.

Many other core Atom language grammars have a foldEndPattern; the regex used in this PR is taken from language-javascript because of the similarity in syntax used for data structures.

Alternate Designs

The regex is ^\\s*\\}|^\\s*\\]|^\\s*\\) in order to fold the end of dictionaries, lists, and functions/tuples, respectively.

The current foldEndPattern in MagicPython is ^\\s*"""\\s*$. The language-python foldEndPattern used to be the same but was removed because the fold would include the beginning """ here:

if True:
    print(True)

"""
A string"""

Since Hydrogen uses Atom's fold regions to determine what code to send to the kernel, it also ran """, which was undesirable.

Benefits

  1. Improve fold behavior by including the ending character (see screenshots below)

Expanded:
image

Current fold behavior:
image

New fold behavior:
image

  1. This would also improve behavior with the Hydrogen package, as that uses Atom's fold regions to decide what block of code to send to the Jupyter kernel. A hacky solution to this was developed (read executed line to get indentation level and expand code nikitakit/hydrogen-python#10, code) in a Python-specific extension to Hydrogen, but the plugin's use is not widespread among all Hydrogen Python users.

Current Hydrogen behavior with ending character on separate line:
image

New Hydrogen behavior with ending character on separate line:

image

Possible Drawbacks

Those who prefer the current behavior could be disappointed? I can't think of any others.

Applicable Issues

@1st1
Copy link
Member

1st1 commented Sep 12, 2018

LGTM. @vpetrovykh please take a look

@vpetrovykh
Copy link
Member

Looks good. Thanks for the detailed explanation and examples!

@vpetrovykh vpetrovykh merged commit cc2b832 into MagicStack:master Sep 12, 2018
@kylebarron
Copy link
Contributor Author

Thanks! It appears that there hasn't been a release since August 2017. Do you have any idea for a timeline of when the next release might happen?

@1st1
Copy link
Member

1st1 commented Sep 12, 2018

I'll cut the next release sometime next week. Thanks!

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.

3 participants