-
-
Notifications
You must be signed in to change notification settings - Fork 136
Add Kitty support #363
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
trekdemo
wants to merge
2
commits into
tpope:master
Choose a base branch
from
trekdemo:kitty-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Add Kitty support #363
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| " dispatch.vim kitty strategy | ||
| " | ||
| " This handler requires you to enable kitty's remote control feature. | ||
| " See https://sw.kovidgoyal.net/kitty/remote-control/ | ||
|
|
||
| if exists('g:autoloaded_dispatch_kitty') | ||
| finish | ||
| endif | ||
| let g:autoloaded_dispatch_kitty = 1 | ||
|
|
||
| let s:waiting = {} | ||
|
|
||
| " ----------------------------------------------------------------------------- | ||
| " Public handler interface | ||
|
|
||
| function! dispatch#kitty#handle(request) abort | ||
| if empty($KITTY_LISTEN_ON) || !executable('kitten') | ||
| return 0 | ||
| endif | ||
|
|
||
| if a:request.action ==# 'make' | ||
| return s:make(a:request) | ||
| elseif a:request.action ==# 'start' | ||
| return s:start(a:request) | ||
| endif | ||
| endfunction | ||
|
|
||
| function! dispatch#kitty#activate(pid) abort | ||
| call system('kitten @ focus-window --match pid:' . a:pid) | ||
| return !v:shell_error | ||
| endfunction | ||
|
|
||
| " ----------------------------------------------------------------------------- | ||
| " Private implementation of the "kitty" handler | ||
|
|
||
| " Handle: :Start, :Spawn | ||
| function! s:start(request) abort | ||
| let cmd = s:kitty_launch_cmd('tab', a:request, dispatch#prepare_start(a:request)) | ||
|
|
||
| call system(cmd) | ||
| return 1 | ||
| endfunction | ||
|
|
||
| " Handle: :Dispatch, :Make | ||
| function! s:make(request) abort | ||
| let qf_height = get(g:, 'dispatch_quickfix_height', 10) | ||
| if get(a:request, 'background', 0) || (qf_height <= 0 && dispatch#has_callback()) | ||
| let type = 'tab' | ||
| else | ||
| let type = 'window' | ||
| endif | ||
|
|
||
| let cmd_with_capturing = a:request.expanded . | ||
| \ '; echo ' . dispatch#status_var() . ' > ' . a:request.file . '.complete' . | ||
| \ '; kitten @ get-text --match=id:$KITTY_WINDOW_ID --ansi=no --extent all > ' . a:request.file | ||
|
|
||
| let cmd = s:kitty_launch_cmd(type, a:request, dispatch#prepare_start(a:request, cmd_with_capturing, 'make')) | ||
| let output = system(cmd) | ||
| let window_id = matchstr(output, '^\d\+$') | ||
|
|
||
| if !empty(window_id) | ||
| let s:waiting[window_id] = a:request | ||
| return 1 | ||
| endif | ||
| endfunction | ||
|
|
||
| " https://sw.kovidgoyal.net/kitty/launch/ | ||
| function! s:kitty_launch_cmd(type, request, command) abort | ||
| let cmd = 'kitten @ launch' | ||
| let cmd .= ' --cwd=' . shellescape(a:request.directory) | ||
| let cmd .= ' --copy-env --env SHLVL --env PWD --env VIM --env VIMRUNTIME --env MYVIMRC --env NVIM_LOG_FILE' | ||
|
|
||
| if a:request.background || a:request.action ==# 'make' | ||
| let cmd .= ' --keep-focus' | ||
| endif | ||
|
|
||
| if a:type ==# 'tab' | ||
| let cmd .= ' --type=tab --tab-title=' . shellescape(a:request.title) | ||
| else | ||
| let cmd .= ' --type=window --location=hsplit --window-title=' . shellescape(a:request.title) | ||
| let bias = get(g:, 'dispatch_kitty_bias', 0) | ||
| if bias != 0 | ||
| let cmd .= ' --bias=' . bias | ||
| endif | ||
| endif | ||
|
|
||
| return cmd . ' sh -c ' . shellescape(a:command) | ||
| endfunction | ||
|
|
||
| " Section: Without callback - polling | ||
|
|
||
| function! s:poll() abort | ||
| if empty(s:waiting) | ||
| return | ||
| endif | ||
|
|
||
| for [window_id, request] in items(s:waiting) | ||
| if !s:kitty_win_exists(window_id) | ||
| call remove(s:waiting, window_id) | ||
| call dispatch#complete(request) | ||
| endif | ||
| endfor | ||
| endfunction | ||
|
|
||
| function! s:kitty_win_exists(wid) abort | ||
| call system('kitten @ ls --match id:' . a:wid) | ||
| return !v:shell_error | ||
| endfunction | ||
|
|
||
| augroup dispatch_kitty | ||
| autocmd! | ||
| autocmd VimResized * nested if !dispatch#has_callback() | call s:poll() | endif | ||
| augroup END | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@trekdemo, for some reason, this was not matching anymore after I updated kitty, maybe a trailing
\n, IDK. Anyway, I think it's safe to just search for the first sequence of digits, no?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was causing dispatch to spawn duplicated jobs, because the kitty one was started, but it failed to get the window_id, so this returns exit code 1 and dispatch would then fallback to the other handlers (jobstart, terminal, etc). The symptom for me was that a quickfix was shown besides at the same time of the kitty window, which didn't bother me in the beginning, until I started getting some problem because of the concurrent processes trying to write to the same SQLite database.