from Vintageous.vi.utils import get_logger

import sublime

import os


class DotFile(object):
    def __init__(self, path):
        self.path = path
        self.logger = get_logger()

    @staticmethod
    def from_user():
        path = os.path.join(sublime.packages_path(), 'User', '.vintageousrc')
        return DotFile(path)

    def run(self):
        try:
            with open(self.path, 'r') as f:
                for line in f:
                    cmd, args = self.parse(line)
                    if cmd:
                        self.logger.info('[DotFile] running: {0} {1}'.format(cmd, args))
                        sublime.active_window().run_command(cmd, args)
        except FileNotFoundError:
            pass

    def parse(self, line):
        self.logger.info('[DotFile] parsing line: {0}'.format(line))
        if line.startswith(':map '):
            line = line[len(':map '):]
            return ('ex_map', {'cmd': line.rstrip()})


@@ -875,24 +875,25 @@
 rtswith(
+(
 ':map ')
 :%0D%0A     
@@ -884,16 +884,17 @@
 ':map ')
+)
 :%0D%0A     
@@ -981,12 +981,290 @@
 trip()%7D)%0D%0A%0D%0A
+        if line.startswith((':omap ')):%0D%0A            line = line%5Blen(':omap '):%5D%0D%0A            return ('ex_omap', %7B'cmd': line.rstrip()%7D)%0D%0A%0D%0A        if line.startswith((':vmap ')):%0D%0A            line = line%5Blen(':vmap '):%5D%0D%0A            return ('ex_vmap', %7B'cmd': line.rstrip()%7D)%0D%0A

add more mapping commands to config file