<commit_before>from __future__ import unicode_literals
from ..line import ClipboardData, SelectionType
from ..keys import Keys
from ..enums import InputMode, IncrementalSearchDirection

from .basic import basic_bindings
from .utils import create_handle_decorator


def emacs_bindings(registry, cli_ref):
    """
    Some e-macs extensions.
    """
    # Overview of Readline emacs commands:
    # http://www.catonmat.net/download/readline-emacs-editing-mode-cheat-sheet.pdf
    basic_bindings(registry, cli_ref)
    line = cli_ref().line
    search_line = cli_ref().lines['search']
    handle = create_handle_decorator(registry, line)

    @handle(Keys.ControlA, in_mode=InputMode.INSERT)
    @handle(Keys.ControlA, in_mode=InputMode.SELECTION)
    def _(event):
        """
        Start of line.
        """
        line.cursor_position += line.document.get_start_of_line_position(after_whitespace=False)

    @handle(Keys.ControlB, in_mode=InputMode.INSERT)
    @handle(Keys.ControlB, in_mode=InputMode.SELECTION)
    def _(event):
        """
        Character back.
        """
        line.cursor_position += line.document.get_cursor_left_position(count=event.arg)

    @handle(Keys.ControlF, in_mode=InputMode.INSERT)
    @handle(Keys.ControlF, in_mode=InputMode.SELECTION)
    def _(event):
        """
        Character forward.
        """
        line.cursor_position += line.document.get_cursor_right_position(count=event.arg)

    @handle(Keys.ControlN, in_mode=InputMode.INSERT)
    def _(event):
        """
        Next line.
        """
        line.auto_down()

    @handle(Keys.ControlN, in_mode=InputMode.SELECTION)
    def _(event):
        """
        Next line.
        """
        line.cursor_down()

    @handle(Keys.ControlO, in_mode=InputMode.INSERT)
    def _(event):
        """
        Insert newline, but don't move the cursor.
        """
        line.insert_text('\n', move_cursor=False)

    @handle(Keys.ControlP, in_mode=InputMode.INSERT)
    def _(event):
        """
        Previous line.
        """
        line.auto_up()

    @handle(Keys.ControlP, in_mode=InputMode.SELECTION)
    def _(event):
        """
        Previous line.
        """
        line.cursor_up()

    @handle(Keys.ControlQ, Keys.Any, in_mode=InputMode.INSERT)
    def _(event):
        """
        Quoted insert.
        """
        line.insert_text(event.data, overwrite=False)

    @handle(Keys.ControlY, in_mode=InputMode.INSERT)
    def _(event):
        """
        Paste before cursor.
        """
        line.paste_from_clipboard(before=True)

    @handle(Keys.ControlUnderscore, save_before=False, in_mode=InputMode.INSERT)
    def _(event):
        """
        Undo.
        """
        line.undo()

    def handle_digit(c):
        """
        Handle Alt + digit in the `meta_digit` method.
        """
        @handle(Keys.Escape, c, in_mode=InputMode.INSERT)
        def _(event):
            event.append_to_arg_count(c)

    for c in '0123456789':
        handle_digit(c)<commit_msg>Implemneted 'arg' for pasting in emacs mode.<commit_after>from __future__ import unicode_literals
from ..line import ClipboardData, SelectionType
from ..keys import Keys
from ..enums import InputMode, IncrementalSearchDirection

from .basic import basic_bindings
from .utils import create_handle_decorator


def emacs_bindings(registry, cli_ref):
    """
    Some e-macs extensions.
    """
    # Overview of Readline emacs commands:
    # http://www.catonmat.net/download/readline-emacs-editing-mode-cheat-sheet.pdf
    basic_bindings(registry, cli_ref)
    line = cli_ref().line
    search_line = cli_ref().lines['search']
    handle = create_handle_decorator(registry, line)

    @handle(Keys.ControlA, in_mode=InputMode.INSERT)
    @handle(Keys.ControlA, in_mode=InputMode.SELECTION)
    def _(event):
        """
        Start of line.
        """
        line.cursor_position += line.document.get_start_of_line_position(after_whitespace=False)

    @handle(Keys.ControlB, in_mode=InputMode.INSERT)
    @handle(Keys.ControlB, in_mode=InputMode.SELECTION)
    def _(event):
        """
        Character back.
        """
        line.cursor_position += line.document.get_cursor_left_position(count=event.arg)

    @handle(Keys.ControlF, in_mode=InputMode.INSERT)
    @handle(Keys.ControlF, in_mode=InputMode.SELECTION)
    def _(event):
        """
        Character forward.
        """
        line.cursor_position += line.document.get_cursor_right_position(count=event.arg)

    @handle(Keys.ControlN, in_mode=InputMode.INSERT)
    def _(event):
        """
        Next line.
        """
        line.auto_down()

    @handle(Keys.ControlN, in_mode=InputMode.SELECTION)
    def _(event):
        """
        Next line.
        """
        line.cursor_down()

    @handle(Keys.ControlO, in_mode=InputMode.INSERT)
    def _(event):
        """
        Insert newline, but don't move the cursor.
        """
        line.insert_text('\n', move_cursor=False)

    @handle(Keys.ControlP, in_mode=InputMode.INSERT)
    def _(event):
        """
        Previous line.
        """
        line.auto_up()

    @handle(Keys.ControlP, in_mode=InputMode.SELECTION)
    def _(event):
        """
        Previous line.
        """
        line.cursor_up()

    @handle(Keys.ControlQ, Keys.Any, in_mode=InputMode.INSERT)
    def _(event):
        """
        Quoted insert.
        """
        line.insert_text(event.data, overwrite=False)

    @handle(Keys.ControlY, in_mode=InputMode.INSERT)
    def _(event):
        """
        Paste before cursor.
        """
        for i in range(event.arg):
            line.paste_from_clipboard(before=True)

    @handle(Keys.ControlUnderscore, save_before=False, in_mode=InputMode.INSERT)
    def _(event):
        """
        Undo.
        """
        line.undo()

    def handle_digit(c):
        """
        Handle Alt + digit in the `meta_digit` method.
        """
        @handle(Keys.Escape, c, in_mode=InputMode.INSERT)
        def _(event):
            event.append_to_arg_count(c)

    for c in '0123456789':
        handle_digit(c)
{'fraction_non_alphanumeric': 0.12093862815884476, 'fraction_numerical': 0.0032819166393173614, 'mean_word_length': 2.500861573808156, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3612706', 'n_tokens_mistral': 1974, 'n_tokens_neox': 1904, 'n_words': 335}