GoogleChromeLabs / text-app

A text editor for ChromeOS and Chrome
https://chrome.google.com/webstore/detail/mmfbcljfglbokpmkimbfghdkjmjhdgbg
Other
551 stars 149 forks source link

Unidenting in Python Alters Program Flow #499

Open albatroxx opened 4 years ago

albatroxx commented 4 years ago

Problem: The unindent command (ie. Shift+Tab) does not correctly identify the desired program flow in Python. This appears to be caused by Python's being an "off-side rule language" (ie. a language that uses whitespace to control program flow, rather than curly braces, begin/end statements, etc.), as it does correctly identify sections of code followed by "pass", "break", or "return" statements. In contrast, it behaves exactly as expected when programming in Rust, C/C++, and Go, all of which use braces to clearly and explicitly delineate program flow. In these languages, the current behavior is much more helpful than the more customary "remove the first indent on each selected line (if any)" behavior. https://en.wikipedia.org/wiki/Off-side_rule#Off-side_rule_languages

Proposed Behavior: When editing a file using an off-side rule language, have the unindent command behave in the more customary fashion by simply remove the first indent on each selected line (if any). The current behavior is preferable otherwise.

Based on a quick look (actually I got curious and did a far more thorough look than was warranted), the only off-side rule languages that appear to have made it only any of the indexes by TIOBE, PYPL, Redmonk, Octoverse.Github, IEEE Spectrum, or StackOverflow's (including the most loved, most hated, and best paying) are Python, Haskell, Elixir, and F#. As such, providing this behavior for these four languages should largely address the issue. These languages have file extensions as follows:

Language    Extensions Used
-------------------------------------
Python:       ".py"
Haskell:      ".hs"
Elixir:       ".ex", ".exs"
F#:           ".fs", ".fsi", ".fsx", ".fsscript"
BugsNash commented 4 years ago

Thanks for filing albatroxx!

We use the CodeMirror library for our text editor in the default mode. This could be an issue in that library, unless there is some setting we can use to allow this type of behavior. More investigation required.