From 1c2f8ba6854c3299efd4380fd0dbfe21c7a43d81 Mon Sep 17 00:00:00 2001 From: cosven Date: Thu, 11 Oct 2018 08:45:48 +0800 Subject: [PATCH 1/2] add command `delete-trailing-whitespace` --- pyvim/commands/commands.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pyvim/commands/commands.py b/pyvim/commands/commands.py index def2a59..1a8d8b2 100644 --- a/pyvim/commands/commands.py +++ b/pyvim/commands/commands.py @@ -1,5 +1,6 @@ from __future__ import unicode_literals, print_function from prompt_toolkit.application import run_in_terminal +from prompt_toolkit.document import Document import os import six @@ -408,6 +409,18 @@ def pwd(editor): editor.show_message('{}'.format(directory)) +@cmd('delete-trailing-whitespace') +def delete_trailing_whitespace(editor): + buffer = editor.current_editor_buffer + l = [] + for line in buffer.text.splitlines(): + l.append(line.rstrip()) + buffer.document = Document( + text='\n'.join(l), + cursor_position=buffer.document.cursor_position + ) + + @location_cmd('cd', accepts_force=False) def pwd(editor, location): " Change working directory. " From cc4da9b80a9e9ea64e383e6c02f8d908822d485a Mon Sep 17 00:00:00 2001 From: cosven Date: Thu, 11 Oct 2018 09:06:06 +0800 Subject: [PATCH 2/2] use buffer instead of editor_buffer --- pyvim/commands/commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyvim/commands/commands.py b/pyvim/commands/commands.py index 1a8d8b2..20a6c47 100644 --- a/pyvim/commands/commands.py +++ b/pyvim/commands/commands.py @@ -411,7 +411,7 @@ def pwd(editor): @cmd('delete-trailing-whitespace') def delete_trailing_whitespace(editor): - buffer = editor.current_editor_buffer + buffer = editor.current_editor_buffer.buffer l = [] for line in buffer.text.splitlines(): l.append(line.rstrip())