<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import vim
import re
import os
import os.path
from functools import wraps
from leaderf.utils import *
from leaderf.explorer import *
from leaderf.manager import *
from leaderf.mru import *


#*****************************************************
# TagExplorer
#*****************************************************
class TagExplorer(Explorer):
    def __init__(self):
        self._tag_list = []

    def getContent(self, *args, **kwargs):
        if self._tag_list:
            return self._tag_list
        else:
            return self.getFreshContent()

    def getFreshContent(self, *args, **kwargs):
        self._tag_list = []
        for tagfile in vim.eval("tagfiles()"):
            with lfOpen(os.path.abspath(tagfile), 'r', errors='ignore') as f:
                taglist = f.readlines()
                self._tag_list.extend(taglist[6:])
        return self._tag_list

    def getStlCategory(self):
        return 'Tag'

    def getStlCurDir(self):
        return escQuote(lfEncode(os.getcwd()))

    def isFilePath(self):
        return False


#*****************************************************
# TagExplManager
#*****************************************************
class TagExplManager(Manager):
    def __init__(self):
        super(TagExplManager, self).__init__()
        self._match_ids = []

    def _getExplClass(self):
        return TagExplorer

    def _defineMaps(self):
        lfCmd("call leaderf#tagExplMaps()")

    def _acceptSelection(self, *args, **kwargs):
        if len(args) == 0:
            return
        line = args[0]
        # {tagname}<Tab>{tagfile}<Tab>{tagaddress}[;"<Tab>{tagfield}..]
        tagname, tagfile, right = line.split('\t', 2)
        res = right.split(';"\t', 1)
        tagaddress = res[0]
        lfCmd("hide edit %s" % escSpecial(tagfile))
        if tagaddress[0] not in '/?':
            lfCmd(tagaddress)
        else:
            lfCmd("norm! gg")

            # In case there are mutiple matches.
            if len(res) > 1:
                result = re.search('(?<=\t)line:\d+', res[1])
                if result:
                    line_num = result.group(0).split(':')[1]
                    lfCmd(line_num)
                else: # for c, c++
                    keyword = "(class|enum|struct|union)"
                    result = re.search('(?<=\t)%s:\S+' % keyword, res[1])
                    if result:
                        tagfield = result.group(0).split(":")
                        name = tagfield[0]
                        value = tagfield[-1]
                        lfCmd("call search('\m%s\_s\+%s\_[^;{]*{', 'w')" % (name, value))

            pattern = "\M" + tagaddress[1:-1]
            lfCmd("call search('%s', 'w')" % escQuote(pattern))

        if lfEval("search('\V%s', 'Wc')" % escQuote(tagname)) == '0':
            lfCmd("norm! ^")

    def _getDigest(self, line, mode):
        """
        specify what part in the line to be processed and highlighted
        Args:
            mode: 0, return the full path
                  1, return the name only
                  2, return the directory name
        """
        if not line:
            return ''
        return line.split('\t', 1)[0]

    def _getDigestStartPos(self, line, mode):
        """
        return the start position of the digest returned by _getDigest()
        Args:
            mode: 0, return the start postion of full path
                  1, return the start postion of name only
                  2, return the start postion of directory name
        """
        return 0
<commit_msg>wrap around<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import vim
import re
import os
import os.path
from functools import wraps
from leaderf.utils import *
from leaderf.explorer import *
from leaderf.manager import *
from leaderf.mru import *


#*****************************************************
# TagExplorer
#*****************************************************
class TagExplorer(Explorer):
    def __init__(self):
        self._tag_list = []

    def getContent(self, *args, **kwargs):
        if self._tag_list:
            return self._tag_list
        else:
            return self.getFreshContent()

    def getFreshContent(self, *args, **kwargs):
        self._tag_list = []
        for tagfile in vim.eval("tagfiles()"):
            with lfOpen(os.path.abspath(tagfile), 'r', errors='ignore') as f:
                taglist = f.readlines()
                self._tag_list.extend(taglist[6:])
        return self._tag_list

    def getStlCategory(self):
        return 'Tag'

    def getStlCurDir(self):
        return escQuote(lfEncode(os.getcwd()))

    def isFilePath(self):
        return False


#*****************************************************
# TagExplManager
#*****************************************************
class TagExplManager(Manager):
    def __init__(self):
        super(TagExplManager, self).__init__()
        self._match_ids = []

    def _getExplClass(self):
        return TagExplorer

    def _defineMaps(self):
        lfCmd("call leaderf#tagExplMaps()")

    def _acceptSelection(self, *args, **kwargs):
        if len(args) == 0:
            return
        line = args[0]
        # {tagname}<Tab>{tagfile}<Tab>{tagaddress}[;"<Tab>{tagfield}..]
        tagname, tagfile, right = line.split('\t', 2)
        res = right.split(';"\t', 1)
        tagaddress = res[0]
        lfCmd("hide edit %s" % escSpecial(tagfile))
        if tagaddress[0] not in '/?':
            lfCmd(tagaddress)
        else:
            lfCmd("norm! gg")

            # In case there are mutiple matches.
            if len(res) > 1:
                result = re.search('(?<=\t)line:\d+', res[1])
                if result:
                    line_num = result.group(0).split(':')[1]
                    lfCmd(line_num)
                else: # for c, c++
                    keyword = "(class|enum|struct|union)"
                    result = re.search('(?<=\t)%s:\S+' % keyword, res[1])
                    if result:
                        tagfield = result.group(0).split(":")
                        name = tagfield[0]
                        value = tagfield[-1]
                        lfCmd("call search('\m%s\_s\+%s\_[^;{]*{', 'w')" % (name, value))

            pattern = "\M" + tagaddress[1:-1]
            lfCmd("call search('%s', 'w')" % escQuote(pattern))

        if lfEval("search('\V%s', 'wc')" % escQuote(tagname)) == '0':
            lfCmd("norm! ^")

    def _getDigest(self, line, mode):
        """
        specify what part in the line to be processed and highlighted
        Args:
            mode: 0, return the full path
                  1, return the name only
                  2, return the directory name
        """
        if not line:
            return ''
        return line.split('\t', 1)[0]

    def _getDigestStartPos(self, line, mode):
        """
        return the start position of the digest returned by _getDigest()
        Args:
            mode: 0, return the start postion of full path
                  1, return the start postion of name only
                  2, return the start postion of directory name
        """
        return 0

{'fraction_non_alphanumeric': 0.18249585864163445, 'fraction_numerical': 0.007730535615681944, 'mean_word_length': 1.9644026186579377, 'pattern_counts': {'":': 2, '<': 13, '<?xml version=': 0, '>': 11, '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': '6583156', 'n_tokens_mistral': 2187, 'n_tokens_neox': 2046, 'n_words': 521}