How to use radian - 10 common examples

To help you get started, we’ve selected a few radian examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github randy3k / radian / radian / console.py View on Github external
else:
                    print("unexpected error was caught.")
                    print("please report to https://github.com/randy3k/radian for such error.")
                    print(e)
                    import traceback
                    traceback.print_exc()
                    import os
                    os._exit(1)

            current_mode = session.current_mode

            if current_mode.on_post_accept:
                result = current_mode.on_post_accept(session)
                if result is not None:
                    return result
                if settings.insert_new_line and current_mode.insert_new_line:
                    app.output.write_raw("\n")
                text = None

        return text
github randy3k / radian / radian / key_bindings.py View on Github external
def _(event):
        text = event.current_buffer.document.text_before_cursor
        textList = text.split("\n")
        if len(textList) >= 2:
            m = re.match(r"^\s*$", textList[-1])
            if m:
                current_indentation = m.group(0)
                previous_indentation = re.match(r"^\s*", textList[-2]).group(0)
                tab_size = settings.tab_size
                if len(current_indentation) >= settings.tab_size and \
                        current_indentation == previous_indentation:
                    event.current_buffer.delete_before_cursor(tab_size)

        event.current_buffer.insert_text(event.data)
github randy3k / radian / radian / key_bindings.py View on Github external
def _(event):
        text = event.current_buffer.document.text_before_cursor
        textList = text.split("\n")
        if len(textList) >= 2:
            m = re.match(r"^\s*$", textList[-1])
            if m:
                current_indentation = m.group(0)
                previous_indentation = re.match(r"^\s*", textList[-2]).group(0)
                tab_size = settings.tab_size
                if len(current_indentation) >= settings.tab_size and \
                        current_indentation == previous_indentation:
                    event.current_buffer.delete_before_cursor(tab_size)

        event.current_buffer.insert_text(event.data)
github randy3k / radian / radian / console.py View on Github external
activated = False
        for name in reversed(session.modes):
            mode = session.modes[name]
            if mode.activator and mode.activator(session):
                session.activate_mode(name)
                activated = True
                break
        if not activated:
            session.activate_mode("unknown")

        current_mode = session.current_mode

        if interrupted[0]:
            interrupted[0] = False
        elif not TERMINAL_CURSOR_AT_BEGINNING[0] or \
                (settings.insert_new_line and current_mode.insert_new_line):
            app.output.write_raw("\n")

        text = None

        while text is None:
            try:
                text = session.prompt(add_history=add_history)

            except KeyboardInterrupt:
                interrupted[0] = True
                raise

            except Exception as e:
                if isinstance(e, EOFError):
                    # todo: confirmation in "r" mode
                    return None
github randy3k / radian / radian / completion.py View on Github external
with suppress_stderr():
            try:
                token = rcompletion.assign_line_buffer(text_before)
                # do not timeout package::func
                if "::" in token or completion_requested:
                    timeout = 0
                else:
                    timeout = self.timeout
                rcompletion.complete_token(timeout)
                completions = rcompletion.retrieve_completions()
            except Exception:
                completions = []

        for c in completions:
            if c.startswith(token) and c != token:
                if c.endswith("=") and settings.completion_adding_spaces_around_equals:
                    c = c[:-1] + " = "
                if c.endswith("::"):
                    # let get_package_completions handles it
                    continue
                yield Completion(c, -len(token))
github randy3k / radian / radian / key_bindings.py View on Github external
def _(event):
        tab_size = settings.tab_size
        buf = event.current_buffer
        leading_spaces = len(buf.document.text_before_cursor)
        buf.delete_before_cursor(min(tab_size, leading_spaces))
github randy3k / radian / radian / key_bindings.py View on Github external
def newline(event, chars=["{", "[", "("]):
    should_indent = event.current_buffer.document.char_before_cursor in chars
    copy_margin = not in_paste_mode() and settings.auto_indentation
    event.current_buffer.newline(copy_margin=copy_margin)
    if should_indent and settings.auto_indentation:
        tab_size = settings.tab_size
        event.current_buffer.insert_text(" " * tab_size)
github randy3k / radian / radian / completion.py View on Github external
def get_completions(self, document, complete_event):
        word = document.get_word_before_cursor()
        prefix_length = settings.completion_prefix_length
        if len(word) < prefix_length and not complete_event.completion_requested:
            return

        latex_comps = list(get_latex_completions(document, complete_event))
        # only return latex completions if prefix has \
        if len(latex_comps) > 0:
            for x in latex_comps:
                yield x
            return

        for x in self.get_r_builtin_completions(document, complete_event):
            yield x
        for x in self.get_package_completions(document, complete_event):
            yield x
github randy3k / radian / radian / completion.py View on Github external
def get_completions(self, document, complete_event):
        word = document.get_word_before_cursor()
        prefix_length = settings.completion_prefix_length
        if len(word) < prefix_length and not complete_event.completion_requested:
            return

        latex_comps = list(get_latex_completions(document, complete_event))
        # only return latex completions if prefix has \
        if len(latex_comps) > 0:
            for x in latex_comps:
                yield x
            return

        for x in self.get_r_completions(document, complete_event):
            yield x
        for x in self.get_package_completions(document, complete_event):
            yield x
github randy3k / radian / radian / key_bindings.py View on Github external
def auto_indentation():
    return settings.auto_indentation