Ejemplo n.º 1
0
 def got_output(text, returncode):
     if text is not None:
         view.append_message(html_string(text, pre=True))
     if returncode:
         if is_ag_installed(ag_path):
             if returncode == 1:
                 message = "no match for pattern: {}".format(pattern)
             else:
                 message = "exit code: {}".format(returncode)
         else:
             message = markdown(AG_NOT_INSTALLED.format(ag_path))
         view.append_message(message, msg_type=const.ERROR)
     if returncode is not None:
         view.process_completed()
Ejemplo n.º 2
0
def pathfind(editor, args):
    """Find file by path"""
    if args is None and editor is not None:
        args = Options(
            path_pattern=get_selection_regex(editor),
            search_path=base_path(editor),
            open="open-single-match",
        )
    if not (args and args.path_pattern):
        from editxt.commands import show_command_bar
        return show_command_bar(editor, "pathfind ")
    pattern = args.path_pattern
    search_path = args.search_path
    regex = re.compile(pattern, pattern.flags)
    if not search_path:
        return "please specify search path"
    paths = []
    exclude = editor.app.config.for_command("pathfind")["exclude_patterns"]
    if args.open == "all-matched-paths":
        is_excluded = lambda path: False
    else:
        excluders = [make_matcher(pattern) for pattern in exclude]
        def is_excluded(path):
            filename = basename(path)
            return any(x(filename) for x in excluders)
    for dirpath, dirnames, filenames in os.walk(search_path):
        if is_excluded(dirpath):
            continue
        for name in filenames:
            path = join(dirpath, name)
            if regex.search(path) and not is_excluded(path):
                paths.append(path)
    if len(paths) == 1 and args.open == "open-single-match":
        editor.project.window.open_paths(paths, focus=True)
    elif paths and args.open == "open-first-match":
        editor.project.window.open_paths(paths[:1], focus=True)
    elif paths:
        link = partial(path_link, editor=editor)
        message = markdown("\n".join(link(path) for path in paths), pre=True)
        editor.message(message)
    else:
        return "no match for pattern: {}".format(args.path_pattern)
Ejemplo n.º 3
0
def markdoc(text, *args, header=True, **kw):
    """Render docstring as markdown

    :param header: When true (the default) make the first line a level-
    one heading (<h1>). Must be specified as keyword argument.
    """
    from editxt.platform.markdown import markdown
    if "\n" not in text:
        first = newline = ""
        rest = text
    else:
        first, newline, rest = text.partition("\n")
        if first.strip():
            if header:
                first = "# " + first
        else:
            first = "# " if header else ""
            newline = ""
    text = "".join([first, newline, dedent(rest)])
    return markdown(text, *args, **kw)