<commit_before>import vdebug.opts
import vdebug.log
import vim
import sys

class Keymapper:
    """Map and unmap key commands for the Vim user interface.
    """

    exclude = ["run","set_breakpoint"]

    def __init__(self):
        self.keymaps = vim.eval("g:vdebug_keymap")
        self.leader = vim.eval("g:vdebug_leader_key")
        self.is_mapped = False

    def map(self):
        if self.is_mapped:
            return
        for func in self.keymaps:
            key = self.keymaps[func]
            if func not in self.exclude:
                map_cmd = "map %s%s :python debugger.%s()<cr>" %\
                    (self.leader,key,func)
                vim.command(map_cmd)
        self.is_mapped = True

    def unmap(self):
        if self.is_mapped:
            self.is_mapped = False

            for func in self.keymaps:
                key = self.keymaps[func]
                if func not in self.exclude:
                    vim.command("unmap %s%s" %(self.leader,key))
<commit_msg>Restoring existing key mappings after debug session, closes #16<commit_after>import vdebug.opts
import vdebug.log
import vim
import sys
import re

class Keymapper:
    """Map and unmap key commands for the Vim user interface.
    """

    exclude = ["run","set_breakpoint"]

    def __init__(self):
        self.keymaps = vim.eval("g:vdebug_keymap")
        self.leader = vim.eval("g:vdebug_leader_key")
        self.is_mapped = False
        self.existing = []

    def map(self):
        if self.is_mapped:
            return
        for func in self.keymaps:
            key = self.keymaps[func]
            if func not in self.exclude:
                vim.command("redir @z | silent map %s%s | redir END" %(self.leader,key))
                self.__save_map_output( vim.eval("@z").strip() )
                map_cmd = "map %s%s :python debugger.%s()<cr>" %\
                    (self.leader,key,func)
                vim.command(map_cmd)
        self.is_mapped = True

    def __save_map_output(self,output):
        if output.startswith('No mapping'):
            return False
        else:
            vdebug.log.Log("Storing existing key mapping, '%s' " % output,\
                    vdebug.log.Logger.DEBUG)
            self.existing.append(output)
            return True

    def unmap(self):
        if self.is_mapped:
            self.is_mapped = False

            for func in self.keymaps:
                key = self.keymaps[func]
                if func not in self.exclude:
                    vim.command("unmap %s%s" %(self.leader,key))
            for mapping in self.existing:
                vdebug.log.Log("Remapping key with '%s' " % mapping,\
                        vdebug.log.Logger.DEBUG)
                vim.command("map %s" % mapping)

{'fraction_non_alphanumeric': 0.10845986984815618, 'fraction_numerical': 0.0007230657989877079, 'mean_word_length': 1.7587238285144566, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1049612', 'n_tokens_mistral': 892, 'n_tokens_neox': 836, 'n_words': 202}