@mastermap.add(Key("V", con=True)) def paste(keys): editor.clipboard.do_paste(cursors.current) @mastermap.add(Key("G", con=True)) def search(keys): editor.buffers.searches.log("s**t") @mastermap.add(Key("X", con=True)) def masterexit(keys): global alive alive = False mastermode.activate() cmd = Command("repeat-string", CommandArg(int, "n" , editor.autocomplete.number()), CommandArg(str, "string")) @cmd.hook(500) def queryish_cb(n, string): cursors.current.insert(string * n) @mastermap.add(Key("R", con=True), Key("e"), Key("p")) def queryish(keys): cmd.run() scroll_selected_face = Face(Face.white, Face.black) @core.windows.hooks.offsety_set(700) def handle_offsety_set(win, old): total = len(win.buffer) before = win.offsety seen = min(total - before, win.textsize[1])
import core.windows from core.key import Key from core.mode import Mode import editor.buffers.ring from editor.command import Command, CommandArg mode = Mode.new(100, "default-buffer") kmap = mode.keymap modifier_key = Key("B", con=True) # buffer-select # # Select the n-th next buffer. Negative values select previous buffers. next_cmd = Command("buffer-next", CommandArg(int, "# buffers to move")) @next_cmd.hook(500) def next_cb(n): w = core.windows.get_selected().buffer buf = editor.buffers.ring.get_id(w, increment=n) w.buffer = buf next_cmd.map_to(kmap, modifier_key, Key("."), defaultargs=[1]) next_cmd.map_to(kmap, modifier_key, Key(","), defaultargs=[-1])
from core.mode import Mode from core.key import Key from editor.command import Command, CommandArg mode = Mode.new(100, "default-cursor") kmap = mode.keymap mapname = "cursor-default" # cursor-up # # Moves the cursor down a specified number of lines. # Negative values move the cursor up. Called with # argument 1 by UP key. up_cmd = Command("cursor-up", CommandArg(int, "Lines to move up")) @up_cmd.hook(500) def up_cb(n): sel = core.cursor.get_selected() sel.move_lines(-n) up_cmd.map_to(kmap, Key("UP"), defaultargs=[1]) # cursor-down # # Moves the cursor down a specified number of lines. # Negative values move the cursor down. Called with # argument 1 by DOWN key. down_cmd = Command("cursor-down", CommandArg(int, "Lines to move down"))
# Splits the currently selected window into two sub-windows. The space occupied # by the original window will be occupied by two windows - The original one, # shrunk to fit, and a new window. The arrangement of these two windows is # determined by the direction argument handed to this command e.g. # # right left up down # +------+-----+ +-----+------+ +------+ +------+ # | | | | | | | new | | orig | # | orig | new | | new | orig | +------+ +------+ # | | | | | | | orig | | new | # +------+-----+ +-----+------+ +------+ +------+ # # The command also spawns a new cursor in the new window, of type # default_cursor_type. (defined in this file.) split_cmd = Command( "window-split", CommandArg(str, "Direction", options("up", "down", "left", "right"))) @split_cmd.hook(500) def split_cb(direction): direction = direction.lower() if direction not in ("up", "down", "left", "right"): return new = core.windows.get_selected().split({ "up": core.windows.direction.up, "down": core.windows.direction.down,
else: break break tomove = len(indent) * n - chars if tomove < 0: cur.move_cols(max(tomove, -cur.cn)) buf[ln] = (indent * n) + text[chars:] if tomove >= 0: cur.move_cols(tomove) indent_cmd = Command("tab-indent", CommandArg(int, "Levels to change")) @indent_cmd.hook(500) def indent_cb(n): cur = core.cursor.get_selected() lvl = get_indent_of_line(cur.buffer, cur.ln) + n if lvl < 0: return set_indent_of_line(cur.buffer, cur.ln, lvl, cur) indent_cmd.map_to(kmap, Key("TAB"), Key("RIGHT"), defaultargs=[1]) indent_cmd.map_to(kmap, Key("TAB"), Key("LEFT"), defaultargs=[-1])
def undefault_cb(subs): Command.set_undefaulted(shlex.split(subs))
import core.deferline from core.mode import Mode from core.key import Key from editor.autocomplete import options_list, number from editor.command import Command, CommandArg, get_command, hooks mode = Mode.new(100, "default-command") kmap = mode.keymap # command-run # # Runs a command of a specific name, with no default arguments. run_cmd = Command("command-run", CommandArg(str, "Name", options_list(Command.names))) @run_cmd.hook(500) def run_cb(name): cmd = get_command(name) cmd.run() run_cmd.map_to(kmap, Key("E", con=True), Key("x")) # command-run-line # # Runs the command on the current line. run_line_cmd = Command("command-run-line")
from core.mode import Mode from core.key import Key from editor.command import Command, CommandArg import editor.autocomplete mode = Mode.new(100, "default-files") kmap = mode.keymap modifier_key = Key("F", con=True) # file-revert # # Load or reload the file associated with the currently selected buffer from # disk. revert_cmd = Command("file-revert") @revert_cmd.hook(500) def revert_cb(): editor.files.revert(core.windows.get_selected().buffer) revert_cmd.map_to(kmap, modifier_key, Key("r")) # file-associate # # Associate a particular file path with the currently selected buffer. associate_cmd = Command( "file-associate", CommandArg(str, "File to associate", editor.autocomplete.path(".")))