Improve Indenting of Blank Lines?

30 views
Skip to first unread message

tbp1...@gmail.com

unread,
Feb 6, 2022, 1:57:17 PM2/6/22
to leo-editor
If you highlight a text block in a node's body that has some blank lines and then indent it - perhaps with <TAB> - The blank lines don't stay blank.  They get padded with spaces to the new left margin.  That's annoying because 1) Leo puts dots in to show you the spaces, which is  visual clutter I'd rather not have, and 2) checker commands like pylint give you warnings about them, so you feel pressed to step through and eliminate all of them.

I'm wondering how feasible it would be to change the indenting code so that blank lines stay blank when a block is indented.  I haven't tried to find that code yet, let alone understand it, so I don't have an opinion about how easy it would be.

Or maybe there is some good (non-programming) reason to keep the current behavior as it is, one that I haven't thought of. 

Does anyone else care about this?  If they do, I'll create a new issue about it.  Otherwise, I suppose it wouldn't be hard to create a user command to clean up a node so that empty lines turn into blank ones.

TEK42

unread,
Feb 6, 2022, 2:32:18 PM2/6/22
to leo-editor
I dislike added whitespace where it is not needed. My preference is to avoid adding whitespace characters to a blank line. I do not envision a case where that would be desired, but I mostly write code and markdown docs.

Cheers,

tbp1...@gmail.com

unread,
Feb 6, 2022, 6:36:48 PM2/6/22
to leo-editor
I've tried this with other common editors and none of them pad the blank lines:

Windows:
Editplus
Notepad++
SciTe
Visual Studio Code

Linux:
Kate
Gedit
Textosaurus
Xed

Pyzo, however, does pad the blank lines.

Looking at the code, I see that the main difficulty would be in figuring out the start and end of the selected region after the indent is calculated, so as to retain the selection.

tbp1...@gmail.com

unread,
Feb 6, 2022, 9:46:49 PM2/6/22
to leo-editor
Here is a script to remove whitespace from all blank lines in a node.  If you have whitespace-padded blank lines after an indent operation, you can run this script to clean them up.  The result can be undone with the usual <CNTL-Z>.  This may be handy until (if ever) the indent operation gets changed to avoid padding blank lines.  Putting the script into a button may be the simplest way to use it.

"""Turn white-space-only lines into blank lines.

Operates on the currently selected node's body.
Does not retain the selected region, if any.
This operation is undoable.
"""

adjusted = []
lines = (line for line in c.p.b.split('\n'))

u = c.undoer
bunch = u.beforeChangeBody(p)

for line in lines:
    if not line.lstrip():
        adjusted.append('')
    else:
        adjusted.append(line)

c.p.b = '\n'.join(adjusted)
c.redraw()
u.afterChangeBody(p, 'Clean Blank Lines', bunch)


Edward K. Ream

unread,
Feb 14, 2022, 5:52:19 PM2/14/22
to leo-editor
On Sun, Feb 6, 2022 at 8:46 PM tbp1...@gmail.com <tbp1...@gmail.com> wrote:
Here is a script to remove whitespace from all blank lines in a node. 

Thanks for this.  I agree that Leo should not pad blank lines when indenting lines.  I have just created #2418 for this issue.

Leo already has the clean-lines and clean-all-lines commands, but they should not be necessary after indenting :-)

Edward
Reply all
Reply to author
Forward
0 new messages