<commit_before># coding: utf-8
import re
import os
import traceback
from urlparse import urlparse

import vim
from floo import dmp_monkey
dmp_monkey.monkey_patch()

from floo import sublime
from floo import AgentConnection
from floo import msg
from floo import shared as G
from floo import utils
from floo.vim_protocol import Protocol


utils.load_settings()

# enable debug with let floo_log_level = 'debug'
floo_log_level = vim.eval('floo_log_level')
if floo_log_level:
    msg.LOG_LEVEL = msg.LOG_LEVELS.get(floo_log_level.upper(), msg.LOG_LEVELS['MSG'])

agent = None


def global_tick():
    """a hack to make vim evented like"""
    if agent:
        agent.tick()
    sublime.call_timeouts()


def CursorHold(*args, **kwargs):
    global_tick()
    vim.command('call feedkeys("f\\e", "n")')


def CursorHoldI(*args, **kwargs):
    global_tick()
    linelen = int(vim.eval("col('$')-1"))
    if linelen > 0:
        if int(vim.eval("col('.')")) == 1:
            vim.command("call feedkeys(\"\<Right>\<Left>\",'n')")
        else:
            vim.command("call feedkeys(\"\<Left>\<Right>\",'n')")
    else:
        vim.command("call feedkeys(\"\ei\",'n')")


# TODO: code smell
def maybeSelectionChanged(*args, **kwargs):
    if agent and agent.protocol:
        agent.protocol.maybe_selection_changed(vim.current.buffer)


def maybeBufferChanged():
    if agent and agent.protocol:
        agent.protocol.maybe_buffer_changed(vim.current.buffer)


def joinroom(room_url):
    global agent
    print("room url is %s" % room_url)
    secure = G.SECURE
    parsed_url = urlparse(room_url)
    port = parsed_url.port<commit_msg>Make a decorator to check for agent and agent.protocol<commit_after># coding: utf-8
import re
import os
import traceback
from urlparse import urlparse

import vim
from floo import dmp_monkey
dmp_monkey.monkey_patch()

from floo import sublime
from floo import AgentConnection
from floo import msg
from floo import shared as G
from floo import utils
from floo.vim_protocol import Protocol


utils.load_settings()

# enable debug with let floo_log_level = 'debug'
floo_log_level = vim.eval('floo_log_level')
if floo_log_level:
    msg.LOG_LEVEL = msg.LOG_LEVELS.get(floo_log_level.upper(), msg.LOG_LEVELS['MSG'])

agent = None


def global_tick():
    """a hack to make vim evented like"""
    if agent:
        agent.tick()
    sublime.call_timeouts()


def CursorHold(*args, **kwargs):
    global_tick()
    vim.command('call feedkeys("f\\e", "n")')


def CursorHoldI(*args, **kwargs):
    global_tick()
    linelen = int(vim.eval("col('$')-1"))
    if linelen > 0:
        if int(vim.eval("col('.')")) == 1:
            vim.command("call feedkeys(\"\<Right>\<Left>\",'n')")
        else:
            vim.command("call feedkeys(\"\<Left>\<Right>\",'n')")
    else:
        vim.command("call feedkeys(\"\ei\",'n')")


def agent_and_protocol(func):
    def wrapped(*args, **kwargs):
        if agent and agent.protocol:
            func(*args, **kwargs)
    return wrapped


@agent_and_protocol
def maybeSelectionChanged(*args, **kwargs):
    agent.protocol.maybe_selection_changed(vim.current.buffer)


@agent_and_protocol
def maybeBufferChanged():
    agent.protocol.maybe_buffer_changed(vim.current.buffer)


@agent_and_protocol
def follow(follow_mode=None):
    agent.protocol.follow(follow_mode)


def joinroom(room_url):
    global agent
    print("room url is %s" % room_url)
    secure = G.SECURE
    parsed_url = urlparse(room_url)
    port = parsed_url.port
{'fraction_non_alphanumeric': 0.13276108726752503, 'fraction_numerical': 0.0022889842632331904, 'mean_word_length': 3.7371273712737128, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '1157113', 'n_tokens_mistral': 1211, 'n_tokens_neox': 1166, 'n_words': 285}