125 lines
3.7 KiB
Python
125 lines
3.7 KiB
Python
import os, commands, re, tempfile
|
|
from subprocess import Popen, PIPE, STDOUT
|
|
|
|
import buffer, default, dirutil, regex, util, window
|
|
from point import Point
|
|
|
|
from method import Method, Argument
|
|
|
|
class _Move(Method):
|
|
'''Abstract base move action'''
|
|
metadata = {'is_move': True}
|
|
|
|
class StartOfLine(_Move):
|
|
'''Move the cursor to the start of the current line'''
|
|
def _execute(self, w, **vargs):
|
|
w.start_of_line()
|
|
class EndOfLine(_Move):
|
|
'''Move the cursor to the end of the current line'''
|
|
def _execute(self, w, **vargs):
|
|
w.end_of_line()
|
|
|
|
class Forward(_Move):
|
|
'''Move the cursor right one character'''
|
|
def _execute(self, w, **vargs):
|
|
w.forward()
|
|
class Backward(_Move):
|
|
'''Move the cursor left one character'''
|
|
def _execute(self, w, **vargs):
|
|
w.backward()
|
|
|
|
class NextLine(_Move):
|
|
'''Move the cursor down one line'''
|
|
def _execute(self, w, **vargs):
|
|
w.next_line()
|
|
class PreviousLine(_Move):
|
|
'''Move the cursor up one line'''
|
|
def _execute(self, w, **vargs):
|
|
w.previous_line()
|
|
|
|
class PageUp(_Move):
|
|
'''Move the cursor up one page'''
|
|
def _execute(self, w, **vargs):
|
|
w.page_up()
|
|
class PageDown(_Move):
|
|
'''Move the cursor down one page'''
|
|
def _execute(self, w, **vargs):
|
|
w.page_down()
|
|
|
|
class GotoBeginning(_Move):
|
|
'''Move the cursor to the beginning of the buffer'''
|
|
def _execute(self, w, **vargs):
|
|
w.set_mark()
|
|
w.goto_beginning()
|
|
class GotoEnd(_Move):
|
|
'''Move the cursor to the end of the buffer'''
|
|
def _execute(self, w, **vargs):
|
|
w.set_mark()
|
|
w.goto_end()
|
|
|
|
class RightWord(_Move):
|
|
'''Move the cursor to the start of the word to the right'''
|
|
def _execute(self, w, **vargs):
|
|
w.right_word()
|
|
class LeftWord(_Move):
|
|
'''Move the cursor to the start of the word to the left'''
|
|
def _execute(self, w, **vargs):
|
|
w.left_word()
|
|
|
|
class NextSection(_Move):
|
|
'''Move the cursor to the next section'''
|
|
def _execute(self, w, **vargs):
|
|
cursor = w.logical_cursor()
|
|
i = cursor.y + 1
|
|
seen_null_line = False
|
|
while i < len(w.buffer.lines):
|
|
if seen_null_line:
|
|
w.goto_line(i)
|
|
break
|
|
seen_null_line = regex.whitespace.match(w.buffer.lines[i])
|
|
i += 1
|
|
class PreviousSection(_Move):
|
|
'''Move the cursor to the previous section'''
|
|
def _execute(self, w, **vargs):
|
|
cursor = w.logical_cursor()
|
|
i = cursor.y - 1
|
|
seen_null_line = False
|
|
while i >= 0:
|
|
if seen_null_line:
|
|
w.goto_line(i)
|
|
break
|
|
seen_null_line = regex.whitespace.match(w.buffer.lines[i])
|
|
i -= 1
|
|
|
|
class GotoChar(_Move):
|
|
'''Jump to the specified character'''
|
|
args = [Argument("charno", type=type(0), prompt="Goto char: ")]
|
|
def _execute(self, w, **vargs):
|
|
w.goto_char(vargs["charno"])
|
|
|
|
class ForwardChars(_Move):
|
|
'''Move forward the specified number of characters'''
|
|
args = [Argument("charno", type=type(0), prompt="Forward chars: ")]
|
|
def _execute(self, w, **vargs):
|
|
w.forward_chars(vargs["charno"])
|
|
|
|
class GotoLine(_Move):
|
|
'''Jump to the specified line number'''
|
|
args = [Argument("lineno", type=type(0), prompt="Goto line: ")]
|
|
def _execute(self, w, **vargs):
|
|
n = vargs["lineno"]
|
|
if n < 0:
|
|
n = len(w.buffer.lines) + n + 1
|
|
if n > len(w.buffer.lines):
|
|
n = len(w.buffer.lines)
|
|
elif n < 1:
|
|
n = 1
|
|
w.goto_line(n)
|
|
|
|
class ForwardLines(_Move):
|
|
'''Move forward the specified number of lines'''
|
|
args = [Argument("lineno", type=type(0), prompt="Forward lines: ")]
|
|
def _execute(self, w, **vargs):
|
|
w.forward_lines(vargs["lineno"])
|
|
|