diff --git a/mode/perl.py b/mode/perl.py index 072080d..8895b33 100644 --- a/mode/perl.py +++ b/mode/perl.py @@ -451,9 +451,9 @@ class PerlWhichFunction(Method): class PerlHashCleanup(Method): '''Correctly align assignment blocks and literal hashes''' - def _execute(self, window, **vargs): - cursor = window.logical_cursor() - b = window.buffer + def _execute(self, w, **vargs): + cursor = w.logical_cursor() + b = w.buffer # so this is where we will store the groups that we find groups_by_line = {} @@ -520,9 +520,12 @@ class PerlHashCleanup(Method): # remove the old text and add the new start_p = Point(0, start) - end_p = Point(0, end + 1) - window.kill(start_p, end_p) - window.insert_string(start_p, data) + if end < len(w.buffer.lines) - 1: + end_p = Point(0, end + 1) + else: + end_p = Point(len(w.buffer.lines[end]), end) + w.kill(start_p, end_p) + w.insert_string(start_p, data) class PerlWrapLine(Method): '''Wrap Comments and POD'''