Пример #1
0
 def rename(self, key=None):
     if key:
         if self.list_entry_for_renaming:
             exit_action_key = self.action_map[action.exit].keybinding
             navigate_mode_action_key = self.action_map[
                 action.navigate_mode].keybinding
             if key in (exit_action_key, navigate_mode_action_key):
                 if key == exit_action_key:
                     new_name = self.list_entry_for_renaming.edit_text
                     operate.rename(self.list_entry_for_renaming.entry,
                                    new_name)
                 self.list_entry_for_renaming.editing = False
                 self.list.render(self.list_size, focus=True)
                 self.list_entry_for_renaming = None
                 self.active_action = None
                 self.enter_navigate_mode()
             else:
                 self.list_entry_for_renaming.keypress(
                     self.filter_size, key)
             return True
         else:
             if self.navigator.is_navigation_key(key):
                 target = self.navigator.current_entry.get_child_for_key(
                     Key(key))
                 notify.clear()
                 list_entry = self.list.get_list_entry(target)
                 if list_entry:
                     list_entry.editing = True
                     self.list.selection = list_entry
                     self.list.render(self.list_size, focus=True)
                     self.list_entry_for_renaming = list_entry
                 return True
     else:
         notify.show("rename what?", duration=0)
         self.active_action = self.rename
Пример #2
0
 def choose_entry(self, key: str):
     if key in key_module.get_all_keys():
         entry = self.navigator.current_entry.get_child_for_key(Key(key))
         assert entry
         self.list.select(entry)
         viewmodel.global_mode.mode = Mode.ASSIGN_CHOOSE_KEY
     elif key == 'enter':
         viewmodel.global_mode.mode = Mode.ASSIGN_CHOOSE_KEY
Пример #3
0
 def delete(self, key=None):
     if key:
         if self.navigator.is_navigation_key(key):
             target = self.navigator.current_entry.get_child_for_key(
                 Key(key))
             buffer.registers[0].move_to(target)
             self.navigator.reload_current_entry()
             self.active_action = None
             self.enter_navigate_mode()
             return True
     else:
         notify.show("delete what?", duration=0)
         self.active_action = self.delete
Пример #4
0
 def yank(self, key=None):
     if key:
         if self.navigator.is_navigation_key(key):
             target = self.navigator.current_entry.get_child_for_key(
                 Key(key))
             buffer.registers[0].copy_to(target)
             notify.show(f"yanked {target.path}")
             self.active_action = None
         self.enter_navigate_mode()
         return True
     else:
         notify.show("yank what?", duration=0)
         self.active_action = self.yank
Пример #5
0
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  |
# +------+-----+ +-----+------+ +------+ +------+
Пример #6
0
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])

align_cmd = Command("tab-align",
                    CommandArg(int, "Relative lineno to copy alignment from"))


@align_cmd.hook(500)
def align_cb(n):
    cur = core.cursor.get_selected()
    ln = cur.ln + n

    if ln < 0:
        return

    if ln > len(cur.buffer):
Пример #7
0
# 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")


@run_line_cmd.hook(500)
def run_line_cb():
    cur = core.cursor.get_selected()
    line = cur.buffer[cur.ln]
    string = bytes(line).decode("utf-8")
    parts = shlex.split(string)
    cmdname = parts[0]
Пример #8
0
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
#