diff --git a/docs/changelog.rst b/docs/changelog.rst index 8d8172405..a5a6c9c27 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -21,6 +21,9 @@ Changelog full-screen/maximized/minimized. This replaces the ``--start-in-fullscreen`` flag introduced in the previous release (:iss:`935`) +- When mapping the new_tab action allow specifying that the tab should open + next to the current tab instead of at the end of the tabs list (:iss:`979`) + - macOS: Add a new :opt:`macos_thicken_font` to make text rendering on macs thicker, which makes it similar to the result of sub-pixel antialiasing (:pull:`950`) diff --git a/kitty/boss.py b/kitty/boss.py index 5531d6ca1..deddd2933 100644 --- a/kitty/boss.py +++ b/kitty/boss.py @@ -850,7 +850,7 @@ class Boss: cmd.append(arg) return SpecialWindow(cmd, stdin, cwd_from=cwd_from) - def _new_tab(self, args, cwd_from=None): + def _new_tab(self, args, cwd_from=None, as_neighbor=False): special_window = None if args: if isinstance(args, SpecialWindowInstance): @@ -859,15 +859,22 @@ class Boss: special_window = self.args_to_special_window(args, cwd_from=cwd_from) tm = self.active_tab_manager if tm is not None: - return tm.new_tab(special_window=special_window, cwd_from=cwd_from) + return tm.new_tab(special_window=special_window, cwd_from=cwd_from, as_neighbor=as_neighbor) + + def _create_tab(self, args, cwd_from=None): + as_neighbor = False + if args and args[0].startswith('!'): + as_neighbor = 'neighbor' in args[0][1:].split(',') + args = args[1:] + self._new_tab(args, as_neighbor=as_neighbor, cwd_from=cwd_from) def new_tab(self, *args): - self._new_tab(args) + self._create_tab(args) def new_tab_with_cwd(self, *args): w = self.active_window cwd_from = w.child.pid if w is not None else None - self._new_tab(args, cwd_from=cwd_from) + self._create_tab(args, cwd_from=cwd_from) def _new_window(self, args, cwd_from=None): tab = self.active_tab diff --git a/kitty/config_data.py b/kitty/config_data.py index 58832e1dc..e37f79a1f 100644 --- a/kitty/config_data.py +++ b/kitty/config_data.py @@ -146,7 +146,12 @@ You can also create shortcuts to go to specific tabs, with 1 being the first tab map ctrl+alt+2 goto_tab 2 Just as with :code:`new_window` above, you can also pass the name of arbitrary -commands to run when using new_tab and use :code:`new_tab_with_cwd`. +commands to run when using new_tab and use :code:`new_tab_with_cwd`. Finally, +if you want the new tab to open next to the current tab rather than at the +end of the tabs list, use:: + + map ctrl+t new_tab !neighbor [optional cmd to run] + ''')], 'shortcuts.layout': [ _('Layout management'), '', diff --git a/kitty/tabs.py b/kitty/tabs.py index 1dd3a810e..236cd76b4 100644 --- a/kitty/tabs.py +++ b/kitty/tabs.py @@ -464,10 +464,16 @@ class TabManager: # {{{ self._set_active_tab(nidx) self.mark_tab_bar_dirty() - def new_tab(self, special_window=None, cwd_from=None): + def new_tab(self, special_window=None, cwd_from=None, as_neighbor=False): + nidx = self.active_tab_idx + 1 idx = len(self.tabs) self._add_tab(Tab(self, special_window=special_window, cwd_from=cwd_from)) self._set_active_tab(idx) + if len(self.tabs) > 2 and as_neighbor and idx != nidx: + self.tabs[idx], self.tabs[nidx] = self.tabs[nidx], self.tabs[idx] + swap_tabs(self.os_window_id, idx, nidx) + self._set_active_tab(nidx) + idx = nidx self.mark_tab_bar_dirty() return self.tabs[idx]