def _load_prompt(self): prompt = roption("radian.prompt", None) if not prompt: sys_prompt = roption("prompt") if sys_prompt == "> ": prompt = PROMPT else: prompt = sys_prompt self._settings["prompt"] = prompt
def hooks(): if not roption("radian.suppress_reticulate_message", False): set_hook(package_event("reticulate", "onLoad"), reticulate_message_hook) if package_is_installed("reticulate") and roption("radian.enable_reticulate_prompt", True): set_hook(package_event("reticulate", "onLoad"), reticulate_prompt_hook) session = get_app().session kb = session.modes["r"].prompt_key_bindings browsekb = session.modes["browse"].prompt_key_bindings @kb.add('~', filter=insert_mode & default_focussed & cursor_at_begin & text_is_empty) @browsekb.add('~', filter=insert_mode & default_focussed & cursor_at_begin & text_is_empty) def _(event): setoption("radian.suppress_reticulate_message", True) commit_text(event, "reticulate::repl_python()", False)
def _(event): # match R behavior editor = roption("editor") if not editor or not isinstance(editor, text_type): if 'VISUAL' in os.environ: editor = os.environ['VISUAL'] elif 'EDITOR' in os.environ: editor = os.environ['EDITOR'] if not editor: editor = "vi" buff = event.current_buffer if editor: orig_visual = os.environ[ 'VISUAL'] if 'VISUAL' in os.environ else None os.environ['VISUAL'] = editor buff.open_in_editor() if editor: def run(): def cleanup(): if orig_visual: os.environ['VISUAL'] = orig_visual else: del os.environ['VISUAL'] yield From(run_in_terminal(cleanup, in_executor=True)) ensure_future(run())
def load(self): self._load_setting("auto_suggest", False, bool) self._load_setting("emacs_bindings_in_vi_insert_mode", False, bool) self._load_setting("editing_mode", "emacs") self._load_setting("color_scheme", "native") self._load_setting("auto_match", True, bool) self._load_setting("highlight_matching_bracket", False, bool) self._load_setting("auto_indentation", True, bool) self._load_setting("tab_size", 4, int) self._load_setting("complete_while_typing", True, bool) self._load_setting("completion_timeout", 0.15) self._load_setting("completion_prefix_length", 2, int) self._load_setting("completion_adding_spaces_around_equals", True, bool) self._load_setting("global_history_file", "~/.radian_history") self._load_setting("local_history_file", ".radian_history") self._load_setting("history_search_no_duplicates", False, bool) self._load_setting("history_search_ignore_case", False, bool) self._load_setting("insert_new_line", True, bool) self._load_setting("indent_lines", True, bool) self._load_prompt() self._load_setting("shell_prompt", SHELL_PROMPT) self._load_setting("browse_prompt", BROWSE_PROMPT) self._load_setting("show_vi_mode_prompt", True, bool) self._load_setting("vi_mode_prompt", VI_MODE_PROMPT) self._load_setting("stderr_format", STDERR_FORMAT) set_width_on_resize = roption("setWidthOnResize", True) self._load_setting("auto_width", set_width_on_resize, bool)
def apply_settings(session, settings): setoption("prompt", settings.prompt) if settings.auto_width: output_width = session.app.output.get_size().columns if output_width: setoption("width", output_width) # necessary on windows setoption("menu.graphics", False) if is_windows() and roption("crayon.enabled", None) is None: setoption("crayon.enabled", True) # enables completion of installed package names if rcopy(rcall(("utils", "rc.settings"), "ipck")) is None: rcall(("utils", "rc.settings"), ipck=True)
def load(self): self._load_setting("editing_mode", "emacs") self._load_setting("color_scheme", "native") self._load_setting("auto_match", False, bool) self._load_setting("auto_indentation", True, bool) self._load_setting("tab_size", 4, int) self._load_setting("complete_while_typing", True, bool) self._load_setting("completion_timeout", 0.05) self._load_setting("history_search_no_duplicates", False, bool) self._load_setting("insert_new_line", True, bool) self._load_setting("indent_lines", True, bool) self._load_prompt() self._load_setting("shell_prompt", SHELL_PROMPT) self._load_setting("browse_prompt", BROWSE_PROMPT) self._load_setting("show_vi_mode_prompt", True, bool) self._load_setting("vi_mode_prompt", VI_MODE_PROMPT) self._load_setting("stderr_format", STDERR_FORMAT) set_width_on_resize = roption("setWidthOnResize", True) self._load_setting("auto_width", set_width_on_resize, bool)
def reticulate_message_hook(*args): if not roption("radian.suppress_reticulate_message", False): rcall("packageStartupMessage", RETICULATE_MESSAGE)
def session_initialize(session): if not sys.platform.startswith("win"): def reticulate_hook(*args): rcall(("base", "source"), os.path.join(os.path.dirname(__file__), "data", "patching_reticulate.R"), new_env()) set_hook(package_event("reticulate", "onLoad"), reticulate_hook) if not roption("radian.suppress_reticulate_message", False): def reticulate_message_hook(*args): if not roption("radian.suppress_reticulate_message", False): rcall("packageStartupMessage", RETICULATE_MESSAGE) set_hook(package_event("reticulate", "onLoad"), reticulate_message_hook) if roption("radian.enable_reticulate_prompt", True): def reticulate_prompt(*args): rcall(("base", "source"), os.path.join(os.path.dirname(__file__), "data", "register_reticulate.R"), new_env()) set_hook(package_event("reticulate", "onLoad"), reticulate_prompt) if roption("radian.editing_mode", "emacs") in ["vim", "vi"]: session.app.editing_mode = EditingMode.VI else: session.app.editing_mode = EditingMode.EMACS color_scheme = roption("radian.color_scheme", "native") session.style = style_from_pygments_cls(get_style_by_name(color_scheme)) session.auto_match = roption("radian.auto_match", False) session.auto_indentation = roption("radian.auto_indentation", True) session.tab_size = int(roption("radian.tab_size", 4)) session.complete_while_typing = roption("radian.complete_while_typing", True) session.completion_timeout = roption("radian.completion_timeout", 0.05) session.history_search_no_duplicates = roption( "radian.history_search_no_duplicates", False) session.insert_new_line = roption("radian.insert_new_line", True) session.indent_lines = roption("radian.indent_lines", True) prompt = roption("radian.prompt", None) if not prompt: sys_prompt = roption("prompt") if sys_prompt == "> ": prompt = PROMPT else: prompt = sys_prompt session.default_prompt = prompt setoption("prompt", prompt) shell_prompt = roption("radian.shell_prompt", SHELL_PROMPT) session.shell_prompt = shell_prompt browse_prompt = roption("radian.browse_prompt", BROWSE_PROMPT) session.browse_prompt = browse_prompt set_width_on_resize = roption("setWidthOnResize", True) session.auto_width = roption("radian.auto_width", set_width_on_resize) output_width = session.app.output.get_size().columns if output_width and session.auto_width: setoption("width", output_width) # necessary on windows setoption("menu.graphics", False) # enables completion of installed package names if rcopy(reval("rc.settings('ipck')")) is None: reval("rc.settings(ipck = TRUE)") # backup the updated settings session._backup_settings()
def enable_reticulate_prompt(): enable = "reticulate" in rcopy(reval("rownames(installed.packages())")) and \ roption("radian.enable_reticulate_prompt", True) if enable: setoption("radian.suppress_reticulate_message", True) return enable
def _load_setting(self, key, default, coercion=lambda x: x): value = roption("radian." + key, default) self._settings[key] = coercion(value)
def load_custom_key_bindings(*args): esc_keymap = roption("radian.escape_key_map", []) for m in esc_keymap: map_key(("escape", m["key"]), m["value"], mode=m["mode"] if "mode" in m else "r")
def run_on_load_hooks(): hooks = roption("radian.on_load_hooks", []) for hook in hooks: hook()
def load_settings(session): if roption("radian.editing_mode", "emacs") in ["vim", "vi"]: session.app.editing_mode = EditingMode.VI else: session.app.editing_mode = EditingMode.EMACS color_scheme = roption("radian.color_scheme", "native") session.style = style_from_pygments_cls(get_style_by_name(color_scheme)) session.auto_match = roption("radian.auto_match", False) session.auto_indentation = roption("radian.auto_indentation", True) session.tab_size = int(roption("radian.tab_size", 4)) session.complete_while_typing = roption("radian.complete_while_typing", True) session.completion_timeout = roption("radian.completion_timeout", 0.05) session.history_search_no_duplicates = roption( "radian.history_search_no_duplicates", False) session.insert_new_line = roption("radian.insert_new_line", True) session.indent_lines = roption("radian.indent_lines", True) prompt = roption("radian.prompt", None) if not prompt: sys_prompt = roption("prompt") if sys_prompt == "> ": prompt = PROMPT else: prompt = sys_prompt session.default_prompt = prompt setoption("prompt", prompt) shell_prompt = roption("radian.shell_prompt", SHELL_PROMPT) session.shell_prompt = shell_prompt browse_prompt = roption("radian.browse_prompt", BROWSE_PROMPT) session.browse_prompt = browse_prompt set_width_on_resize = roption("setWidthOnResize", True) session.auto_width = roption("radian.auto_width", set_width_on_resize) output_width = session.app.output.get_size().columns if output_width and session.auto_width: setoption("width", output_width) # necessary on windows setoption("menu.graphics", False) # enables completion of installed package names if rcopy(reval("rc.settings('ipck')")) is None: reval("rc.settings(ipck = TRUE)") # backup the updated settings session._backup_settings()