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

Indent lines containing blank lines #93

Closed
allanderek opened this issue Dec 4, 2013 · 2 comments
Closed

Indent lines containing blank lines #93

allanderek opened this issue Dec 4, 2013 · 2 comments

Comments

@allanderek
Copy link
Contributor

If you indent a set of lines which contains a blank line, then arguably any blank lines should not themselves be indented. At least not for most programming languages. So it is arguable as to whether this can be considered an issue within editorcommands.py or its interface with each mode.

To be clear here is an example:

def some_method(arg):
    """ A doc string"""

    return blah(arg)

In the current implementation the blank line between the doc string and the return statement is indented along with the rest of the method definition, whereas generally we would wish for the blank line to remain blank (for example pep8 would complain about 'trailing whitespace').

I have a solution to this in editorcommands.indent:

    s = mode.build_indent_str(cols + mode.indent_width)
    self.replace_string(wnd, f, t, s, False)
    tol = doc.geteol(tol)
finally:

becomes:

    eol = doc.geteol(tol)
    if eol != t+1:
        s = mode.build_indent_str(cols + mode.indent_width)
        self.replace_string(wnd, f, t, s, False)
    tol = doc.geteol(tol)
finally:

Before I submit a pull request, does this seem like a reasonable solution? I cannot seem to avoid calling doc.geteol(tol) twice.
Additionally, why does indent not simply call self._indent_line on each line within the selection? If it did then to fix this issue, _indent_line would probably need an argument to say whether it should indent a blank line or not.

@atsuoishimoto
Copy link
Member

Hi, thank you for issue.

I'm fully agree that blank line should not be indented, and your fix looks good to me.

Using EditCommands._indent_line() on each line of text is okay, but it requires some more changes. Current EditCommands._indent_line() checks if cursor position is in indentation in the line or not. If text is not selected and cursor position is beyond indentation characters, line should not be indent line but simply put tab character at cursor position. I don't think new argument to indent blank line is necessary.

allanderek added a commit to allanderek/kaa that referenced this issue Dec 4, 2013
…lection of lines are indented. This prevents that and adds a regression test for it to test_editorcommands.py
@atsuoishimoto
Copy link
Member

Merged PR #94.

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

No branches or pull requests

2 participants