kakounedotcom / connect.kak

Connect a program to Kakoune clients
https://kakoune.org
The Unlicense
88 stars 18 forks source link

Adds the ability to focus kakoune on `open` #14

Closed xxxserxxx closed 4 years ago

xxxserxxx commented 4 years ago

I use connect mostly with nnn as a sort of project manager. More often than not, after opening a file in nnn, I want focus to return to kakoune. This patch adds that ability.

When the option connect_focus is set, edit will focus the window containing kakoune. This works reliably with i3, because both kakoune and i3 provide good information and mechanisms for making it happen. It works with tmux if the user doesn't move panes around; this limitation is due to the fact that there's no way to focus a pane by name, and wouldn't even if it could because kakoune doesn't set a pane title. However, the default behavior -- of opening a tmux pane to the right -- is assumed and control is return to the pane to the left. There is no functionality for any other window manager.

The script tries to do the right thing: it only does its thing if the connect_focus option is set; then it tries to detect if it is running in tmux, and if so, tries to return focus that way; then if not, it tries to do it with i3.

Example use:

: set-option buffer connect_focus 1
: connect-terminal sh -c '(NNN_OPENER=edit nnn)'

select a file in nnn and hit .

alexherbo2 commented 4 years ago

x11.kak and tmux.kak have a focus command to focus clients, so we can use that command with send focus from the shell.

xxxserxxx commented 4 years ago

@alexherbo2 focus is way better than i3-msg. What about:

  1. tmux -- it appears to be a common use case, and focus doesn't help
  2. the original behavior was to not revert focus, which is why I made it an option

Aren't you concerned about backwards compatability here? People who pull this are going to be in for a surprise when the behavior suddenly changes.

alexherbo2 commented 4 years ago

I don’t care about backward compatibility, but if it bothers users, I will change it or add an option.