kakoune/rc/windowing/repl/x11.kak
Johannes Altmanninger 746e0d032f rc windowing: allow to configure windowing system and window placement in new/terminal commands
Today I can control "terminal" and "new" by changing the terminal
alias but I always need to choose a concrete implementation, like
"tmux-terminal-horizontal", even when there is otherwise no need to
mention tmux in my config.

Allow to configure windowing system and window placement independently
by introducing dedicated options.

This allows to create mappings that work in any windowing system like

	map global user c   %{:with-option windowing_placement window new<ret>}
	map global user '"' %{:with-option windowing_placement vertical new<ret>}
	map global user '%' %{:with-option windowing_placement horizontal new<ret>}

For windowing systems that don't support all placements, you can wrap
the above in try/catch to fall back on the "window" variant which is
defined for all windowing systems.

When using multiple (nested) windowing systems, you might want to
add mappings like

	map global user t %{:with-option windowing_module tmux new<ret>}
	map global user T %{:with-option windowing_module wayland new<ret>}

---

This changes the default "terminal" alias for some modules. In
particular, instead of delegating to

    iterm-terminal-vertical
    screen-terminal-vertical
    tmux-terminal-horizontal
    wezterm-terminal-vertical

it will now by default delegate to the respective "-window" variant.
We could maintain backwards compatiblity here by setting the
"windowing_placement" option accordingly, but the new behavior seems
more logical?

Also, this removes the "terminal-tab" alias which was only defined
by the kitty module.

We could try to keep the alias approach and implement a "with-alias"
command, however that approach can only capture both dimensions
(windowing system and placement) if we add tons of commands
like "terminal-horizontal" (with implied windowing system) and
"tmux-terminal" (with implied placement).

Side thought: we could also get rid of the "focus" alias and instead
define

    define-command focus %{
        "%opt{windowing_module}-focus"
    }

Closes #3943, #4425
2023-11-13 22:54:49 +01:00

42 lines
1.4 KiB
Plaintext

hook global ModuleLoaded x11 %{
require-module x11-repl
}
provide-module x11-repl %{
declare-option -docstring "window id of the REPL window" str x11_repl_id
define-command -docstring %{
x11-repl [<arguments>]: create a new window for repl interaction
All optional parameters are forwarded to the new window
} \
-params .. \
x11-repl %{ x11-terminal-window sh -c %{
winid="${WINDOWID:-$(xdotool search --pid ${PPID} | tail -1)}"
printf "evaluate-commands -try-client $1 \
'set-option current x11_repl_id ${winid}'" | kak -p "$2"
shift 2;
[ "$1" ] && "$@" || "$SHELL"
} -- %val{client} %val{session} %arg{@}
}
complete-command x11-repl shell
define-command x11-send-text -params 0..1 -docstring %{
x11-send-text [text]: Send text to the REPL window.
If no text is passed, then the selection is used
} %{
evaluate-commands %sh{
([ "$#" -gt 0 ] && printf "%s" "$1" || printf "%s" "${kak_selection}" ) | xsel -i ||
echo 'fail x11-send-text: failed to run xsel, see *debug* buffer for details' &&
kak_winid=$(xdotool getactivewindow) &&
xdotool windowactivate "${kak_opt_x11_repl_id}" key --clearmodifiers Shift+Insert &&
xdotool windowactivate "${kak_winid}" ||
echo 'fail x11-send-text: failed to run xdotool, see *debug* buffer for details'
}
}
alias global repl-new x11-repl
alias global repl-send-text x11-send-text
}