Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Add foldEndPattern to settings #274

Merged
merged 2 commits into from
Nov 13, 2018
Merged

Add foldEndPattern to settings #274

merged 2 commits into from
Nov 13, 2018

Conversation

kylebarron
Copy link
Contributor

@kylebarron kylebarron commented Sep 11, 2018

Description of the Change

Add a value for foldEndPattern in the package settings. This improves the folding behavior for dictionaries, lists, and functions when not using the tree-sitter parser. 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.

At first thought, it might be desirable to add ^\\s*""" to the regex in order to fold multi-line strings, but since the same characters are used to open a multiline string, this can create bugs. In fact, this used to be the value of foldEndPattern in this package, but was removed upon unintended effects used with Hydrogen.

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

@rgbkrk
Copy link

rgbkrk commented Sep 12, 2018

This would be fantastic for us in nteract's hydrogen @maxbrunsfeld. 🙇 Thank you for all the Atoms.

@kylebarron
Copy link
Contributor Author

Just pinging another maintainer @50Wliu. It would be great if this could be included in the next release of Atom.

@lee-dohm
Copy link
Contributor

Would you mind taking a look at this when you get the chance @50Wliu ?

@kylebarron
Copy link
Contributor Author

Just pinging again.

Copy link
Contributor

@50Wliu 50Wliu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a minor syntactic change to shorten the regex, but otherwise this looks good.

settings/language-python.cson Outdated Show resolved Hide resolved
Co-Authored-By: kylebarron <kylebarron2@gmail.com>
@50Wliu 50Wliu merged commit 56e2f1c into atom:master Nov 13, 2018
@50Wliu
Copy link
Contributor

50Wliu commented Nov 13, 2018

Sorry for the delay!

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

Successfully merging this pull request may close these issues.

None yet

4 participants