def addlineno(w, b, ln, li): face = Face(Face.black, Face.black, bright=True) prefix = hex(ln.value)[2:].zfill(4) + "» " prefix = face.serialize(len(prefix)) + prefix.encode("utf-8") li.insert_at_byte(0, prefix) @core.deferline.hooks.draw(900) def addeol(w, b, ln, li): face = Face(Face.black, Face.black, bright=True) suffix = "«" suffix = b" " + face.serialize(len(suffix)) + suffix.encode("utf-8") li.insert_at_byte(len(li.vec), suffix) mastermode = Mode.new(100, "default-master") mastermap = mastermode.keymap @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()
Arguments: string (str, bytes): The new contents of the response. """ if isinstance(string, bytes): string = string.decode("ascii") self.string = list(string) self.cn = len(string) self.draw() QueryCursorType = CursorType(QueryCursor) query_mode = Mode.new_cursor(80, "query") query_kmap = query_mode.keymap core.cursor.snap_blacklist.insert(0, QueryCursorType.struct) querying_buffers = set() def autocomplete_query(): curcursor = core.cursor.get_selected() curinst = QueryCursorType.find_instance(curcursor) if not isinstance(curinst, QueryCursor): raise Exception("Current cursor is not a query cursor") auto = curinst.autocompleter.complete("".join(curinst.string))
import string import editor.buffers.userlog import core.cursor 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 #
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])
import core.windows import editor.buffers.userlog from core.mode import Mode from core.key import Key from editor.autocomplete import options from editor.command import Command, CommandArg mode = Mode.new(100, "default-window") kmap = mode.keymap modifier_key = Key("W", con=True) default_cursor_type = core.cursor.types.region # window-split # # # 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 | # +------+-----+ +-----+------+ +------+ +------+
import itertools import core.cursor import core.deferline import core.ui from core.mode import Mode from core.key import Key from core.face import Face from editor.command import Command, CommandArg mapname = "tabs-default" mode = Mode.new(100, "default-tabs") kmap = mode.keymap default_tab_string = b" " + Face(Face.black, Face.cyan).colour(b">") default_indent_string = b" " default_tab_align = True """Hooked function to display tabs properly. This function expands tab characters in each line that's rendered into default_tab_string. This is generally to make them more visible. """ @core.deferline.hooks.draw(600) def expandtabs(w, b, ln, li): tab = get_tab_string(b) align = get_tab_align(b)
import shlex import core.cursor 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
import os.path import core.windows 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 #