(self, path: str, line_number: int | None)
| 438 | return results[:limit] |
| 439 | |
| 440 | def open_in_editor(self, path: str, line_number: int | None) -> bool: |
| 441 | try: |
| 442 | # First try to get editor from environment variable |
| 443 | editor = os.environ.get("EDITOR") |
| 444 | |
| 445 | # If editor is a terminal-based editor, we just call `open`, because |
| 446 | # otherwise it silently opens the terminal in the same window that is |
| 447 | # running marimo. |
| 448 | if editor and not _is_terminal_editor(editor): |
| 449 | args = ( |
| 450 | [path] |
| 451 | if line_number is None |
| 452 | else editor_open_file_in_line_args( |
| 453 | editor, path, line_number |
| 454 | ) |
| 455 | ) |
| 456 | |
| 457 | try: |
| 458 | # For GUI editors |
| 459 | subprocess.run([editor, *args]) |
| 460 | return True |
| 461 | except Exception as e: |
| 462 | LOGGER.error(f"Error opening with EDITOR: {e}") |
| 463 | |
| 464 | # Use system default if no editor specified |
| 465 | if platform.system() == "Darwin": # macOS |
| 466 | subprocess.call(("open", path)) |
| 467 | elif platform.system() == "Windows": # Windows |
| 468 | # startfile only exists on Windows |
| 469 | os.startfile(path) # type: ignore[attr-defined] |
| 470 | else: # Linux variants |
| 471 | subprocess.call(("xdg-open", path)) |
| 472 | return True |
| 473 | except Exception as e: |
| 474 | LOGGER.error(f"Error opening file: {e}") |
| 475 | return False |
| 476 | |
| 477 | |
| 478 | def editor_open_file_in_line_args( |
no test coverage detected