2020-08-31 20:58:27 -04:00
|
|
|
import os, subprocess, re, tempfile
|
2008-03-17 03:16:15 -04:00
|
|
|
from subprocess import Popen, PIPE, STDOUT
|
|
|
|
|
|
|
|
import buffer, default, dirutil, regex, util, window
|
|
|
|
from point import Point
|
|
|
|
|
2008-11-08 11:18:48 -05:00
|
|
|
from method import Method, Argument
|
2008-03-17 03:16:15 -04:00
|
|
|
|
2009-03-19 00:23:09 -04:00
|
|
|
class _Move(Method):
|
|
|
|
'''Abstract base move action'''
|
|
|
|
metadata = {'is_move': True}
|
|
|
|
|
|
|
|
class StartOfLine(_Move):
|
2008-03-17 03:16:15 -04:00
|
|
|
'''Move the cursor to the start of the current line'''
|
|
|
|
def _execute(self, w, **vargs):
|
|
|
|
w.start_of_line()
|
2009-03-19 00:23:09 -04:00
|
|
|
class EndOfLine(_Move):
|
2008-03-17 03:16:15 -04:00
|
|
|
'''Move the cursor to the end of the current line'''
|
|
|
|
def _execute(self, w, **vargs):
|
|
|
|
w.end_of_line()
|
|
|
|
|
2009-03-19 00:23:09 -04:00
|
|
|
class Forward(_Move):
|
2008-03-17 03:16:15 -04:00
|
|
|
'''Move the cursor right one character'''
|
|
|
|
def _execute(self, w, **vargs):
|
|
|
|
w.forward()
|
2009-03-19 00:23:09 -04:00
|
|
|
class Backward(_Move):
|
2008-03-17 03:16:15 -04:00
|
|
|
'''Move the cursor left one character'''
|
|
|
|
def _execute(self, w, **vargs):
|
|
|
|
w.backward()
|
|
|
|
|
2009-03-19 00:23:09 -04:00
|
|
|
class NextLine(_Move):
|
2008-03-17 03:16:15 -04:00
|
|
|
'''Move the cursor down one line'''
|
|
|
|
def _execute(self, w, **vargs):
|
|
|
|
w.next_line()
|
2009-03-19 00:23:09 -04:00
|
|
|
class PreviousLine(_Move):
|
2008-03-17 03:16:15 -04:00
|
|
|
'''Move the cursor up one line'''
|
|
|
|
def _execute(self, w, **vargs):
|
|
|
|
w.previous_line()
|
|
|
|
|
2009-03-19 00:23:09 -04:00
|
|
|
class PageUp(_Move):
|
2008-03-17 03:16:15 -04:00
|
|
|
'''Move the cursor up one page'''
|
|
|
|
def _execute(self, w, **vargs):
|
|
|
|
w.page_up()
|
2009-03-19 00:23:09 -04:00
|
|
|
class PageDown(_Move):
|
2008-03-17 03:16:15 -04:00
|
|
|
'''Move the cursor down one page'''
|
|
|
|
def _execute(self, w, **vargs):
|
|
|
|
w.page_down()
|
|
|
|
|
2009-03-19 00:23:09 -04:00
|
|
|
class GotoBeginning(_Move):
|
2008-03-17 03:16:15 -04:00
|
|
|
'''Move the cursor to the beginning of the buffer'''
|
|
|
|
def _execute(self, w, **vargs):
|
2008-11-08 11:18:48 -05:00
|
|
|
w.set_mark()
|
2008-03-17 03:16:15 -04:00
|
|
|
w.goto_beginning()
|
2009-03-19 00:23:09 -04:00
|
|
|
class GotoEnd(_Move):
|
2008-03-17 03:16:15 -04:00
|
|
|
'''Move the cursor to the end of the buffer'''
|
|
|
|
def _execute(self, w, **vargs):
|
2008-11-08 11:18:48 -05:00
|
|
|
w.set_mark()
|
2008-03-17 03:16:15 -04:00
|
|
|
w.goto_end()
|
|
|
|
|
2009-03-19 00:23:09 -04:00
|
|
|
class RightWord(_Move):
|
2008-03-17 03:16:15 -04:00
|
|
|
'''Move the cursor to the start of the word to the right'''
|
|
|
|
def _execute(self, w, **vargs):
|
|
|
|
w.right_word()
|
2009-03-19 00:23:09 -04:00
|
|
|
class LeftWord(_Move):
|
2008-03-17 03:16:15 -04:00
|
|
|
'''Move the cursor to the start of the word to the left'''
|
|
|
|
def _execute(self, w, **vargs):
|
|
|
|
w.left_word()
|
|
|
|
|
2009-03-19 00:23:09 -04:00
|
|
|
class NextSection(_Move):
|
2008-03-17 03:16:15 -04:00
|
|
|
'''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
|
2009-03-19 00:23:09 -04:00
|
|
|
class PreviousSection(_Move):
|
2008-03-17 03:16:15 -04:00
|
|
|
'''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
|
|
|
|
|
2009-03-19 00:23:09 -04:00
|
|
|
class GotoChar(_Move):
|
2008-03-17 03:16:15 -04:00
|
|
|
'''Jump to the specified character'''
|
|
|
|
args = [Argument("charno", type=type(0), prompt="Goto char: ")]
|
|
|
|
def _execute(self, w, **vargs):
|
|
|
|
w.goto_char(vargs["charno"])
|
|
|
|
|
2009-03-19 00:23:09 -04:00
|
|
|
class ForwardChars(_Move):
|
2008-03-17 03:16:15 -04:00
|
|
|
'''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"])
|
|
|
|
|
2009-03-19 00:23:09 -04:00
|
|
|
class GotoLine(_Move):
|
2008-03-17 03:16:15 -04:00
|
|
|
'''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)
|
|
|
|
|
2009-03-19 00:23:09 -04:00
|
|
|
class ForwardLines(_Move):
|
2008-03-18 10:51:47 -04:00
|
|
|
'''Move forward the specified number of lines'''
|
2008-03-17 03:16:15 -04:00
|
|
|
args = [Argument("lineno", type=type(0), prompt="Forward lines: ")]
|
|
|
|
def _execute(self, w, **vargs):
|
|
|
|
w.forward_lines(vargs["lineno"])
|
|
|
|
|