Message346937
> 1. The name `formatregion` could probably be improved.
FormatRegion is good enough, and is consistent with FormatParagraph.
> 2. The `classifyws` method is a module level method in editor. It's needed in `formatregion` also, so I made a copy (bad!). I would have liked to create a `utils.py` for this, but maybe there's a better place for it? It doesn't just operate on text widgets as it is just a string function. I'm sure there's an obvious choice that I'm missing. See also #4 below.
As you're just trying to refactor with minimal changes, this can just stay as-is IMO.
My optimal end solution would be:
1. remove classifyws()
2. create get_line_indent(line) function which returns re.match(r'[ \t]*', line).end()
3. use len(indent) and/or len(indent.expandtabs(tabwidth)) as needed.
4. get_line_indent(line) is so simple that having it duplicated would be fine IMHO.
> 3. `tabwidth` and `indentwidth` in `formatregion` are getting the values from the editor window. I thought about adding those to the init for FormatRegion, but then they would need to be updated if config changed. Not sure which way would be better.
I say, leave this the way it is.
> 4. Other methods in editor might be candidates for moving, such as the auto-indent methods (search on `### begin autoindent code ###` in editor) and specifically `smart_indent_event`. Moving more of the indent code to a separate module helps with #2 and #3 above, but I wasn't sure how much of the text formatting should be moved. I thought it best to start with the minimal change.
I wouldn't move event handlers. I will say that the code in some of those functions could use a bit of cleanup and standardization WRT indentation handling, e.g. using get_line_indent() as described above in a few places where it is naively re-implemented with a loop. |
|
| Date |
User |
Action |
Args |
| 2019-06-30 19:53:23 | taleinat | set | recipients:
+ taleinat, terry.reedy, cheryl.sabella |
| 2019-06-30 19:53:23 | taleinat | set | messageid: <1561924403.89.0.265122394537.issue36390@roundup.psfhosted.org> |
| 2019-06-30 19:53:23 | taleinat | link | issue36390 messages |
| 2019-06-30 19:53:23 | taleinat | create | |
|