From c3c99113c7f06193d0fcca914a208adc9267a855 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 4 Mar 2024 21:49:06 +0530 Subject: [PATCH] hints kitten: Use default editor rather than hardcoding vim to open file at specific line Fixes #7186 --- docs/changelog.rst | 2 ++ docs/kittens/hints.rst | 6 ++++-- kittens/hints/main.py | 7 +++++-- kitty/options/definition.py | 2 +- 4 files changed, 12 insertions(+), 5 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index e36941add..00de136d7 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -81,6 +81,8 @@ Detailed list of changes - kitten @ ls: Return the timestamp at which the window was created (:iss:`7178`) +- hints kitten: Use default editor rather than hardcoding vim to open file at specific line (:iss:`7186`) + 0.32.2 [2024-02-12] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/kittens/hints.rst b/docs/kittens/hints.rst index 73d58e597..69edeb8e8 100644 --- a/docs/kittens/hints.rst +++ b/docs/kittens/hints.rst @@ -26,8 +26,10 @@ and adding them to the command line for the next command. You can also press :sc:`goto_file_line` to select anything that looks like a path or filename followed by a colon and a line number and open the file in -:program:`vim` at the specified line number. The patterns and editor to be used -can be modified using options passed to the kitten. For example:: +your default editor at the specified line number (opening at line number will +work only if your editor supports the +linenum command line syntax or is a +"known" editor). The patterns and editor to be used can be modified using +options passed to the kitten. For example:: map ctrl+g kitten hints --type=linenum --linenum-action=tab nvim +{line} {path} diff --git a/kittens/hints/main.py b/kittens/hints/main.py index 1a9c71e48..bf5041443 100644 --- a/kittens/hints/main.py +++ b/kittens/hints/main.py @@ -10,7 +10,7 @@ from kitty.clipboard import set_clipboard_string, set_primary_selection from kitty.constants import website_url from kitty.fast_data_types import get_options from kitty.typing import BossType -from kitty.utils import resolve_custom_file +from kitty.utils import get_editor, resolve_custom_file from ..tui.handler import result_handler @@ -272,7 +272,10 @@ def linenum_handle_result(args: List[str], data: Dict[str, Any], target_window_i if not path: return - cmd = [x.format(path=path, line=line) for x in extra_cli_args or ('vim', '+{line}', '{path}')] + if extra_cli_args: + cmd = [x.format(path=path, line=line) for x in extra_cli_args] + else: + cmd = get_editor(path_to_edit=path, line_number=line) w = boss.window_id_map.get(target_window_id) action = data['linenum_action'] diff --git a/kitty/options/definition.py b/kitty/options/definition.py index a368fc4f6..42a177bdb 100644 --- a/kitty/options/definition.py +++ b/kitty/options/definition.py @@ -4031,7 +4031,7 @@ map('Open the selected file at the selected line', 'goto_file_line kitty_mod+p>n kitten hints --type linenum', long_text=''' Select something that looks like :code:`filename:linenum` and open it in -:program:`vim` at the specified line number. +your default editor at the specified line number. ''' )