Last active
August 29, 2015 14:06
-
-
Save badosu/8bab3b96ae2b364addb6 to your computer and use it in GitHub Desktop.
A vim-dispatch handler for dvtm
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
let g:dispatch_handlers = [ | |
\ 'tmux', | |
\ 'dvtm', | |
\ 'screen', | |
\ 'windows', | |
\ 'iterm', | |
\ 'x11', | |
\ 'headless', | |
\ ] |
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
diff --git a/config.def.h b/config.def.h | |
index 047aa3e..3c0e8d6 100644 | |
--- a/config.def.h | |
+++ b/config.def.h | |
@@ -146,7 +146,10 @@ static Button buttons[] = { | |
#endif /* CONFIG_MOUSE */ | |
static Cmd commands[] = { | |
- { "create", { create, { NULL } } }, | |
+ { "create", { create, { NULL } } }, | |
+ { "focusn", { focusn, { NULL } } }, | |
+ { "setmfact", { setmfact, { NULL } } }, | |
+ { "setlayout", { setlayout, { NULL } } } | |
}; | |
/* gets executed when dvtm is started */ | |
diff --git a/dvtm.c b/dvtm.c | |
index 71ffccb..055d982 100644 | |
--- a/dvtm.c | |
+++ b/dvtm.c | |
@@ -787,7 +787,7 @@ copymode(const char *args[]) { | |
static void | |
focusn(const char *args[]) { | |
for (Client *c = clients; c; c = c->next) { | |
- if (c->order == atoi(args[0])) { | |
+ if (c->id == atoi(args[0])) { | |
focus(c); | |
if (c->minimized) | |
toggleminimize(NULL); |
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
if exists('g:autoloaded_dispatch_dvtm') | |
finish | |
endif | |
let g:autoloaded_dispatch_dvtm = 1 | |
let s:waiting = {} | |
function! dispatch#dvtm#handle(request) abort | |
if empty($DVTM_CMD_FIFO) | |
return 0 | |
endif | |
if a:request.action ==# 'make' | |
return dispatch#dvtm#spawn(dispatch#prepare_make(a:request), a:request) | |
elseif a:request.action ==# 'start' | |
return dispatch#dvtm#spawn(dispatch#prepare_start(a:request), a:request) | |
endif | |
endfunction | |
function! dispatch#dvtm#spawn(command, request) abort | |
let s:waiting[a:request.file] = a:request | |
let script = dispatch#isolate([], dispatch#set_title(a:request), a:command) | |
let command = shellescape(&shell.' '.&shellcmdflag." '".script."'") | |
if a:request.background | |
call dispatch#dvtm#send("setlayout '[ ]'") | |
else | |
call dispatch#dvtm#send("setlayout 'TTT'") | |
call dispatch#dvtm#send("setmfact 0.3") | |
endif | |
call dispatch#dvtm#send('create '.command) | |
call dispatch#dvtm#send('focusn '.$DVTM_WINDOW_ID) | |
return 1 | |
endfunction | |
function! dispatch#dvtm#send(command) abort | |
silent execute '!echo "'.a:command.'" > '.$DVTM_CMD_FIFO | |
return !v:shell_error | |
endfunction | |
function! dispatch#dvtm#poll() abort | |
for [file, request] in items(s:waiting) | |
if filereadable(file.'.complete') | |
call remove(s:waiting, file) | |
call dispatch#complete(request) | |
endif | |
endfor | |
endfunction | |
function! dispatch#dvtm#activate(pid) abort | |
let window = matchstr(system('ps ewww -p '.a:pid), 'DVTM_WINDOW_ID=\zs\d\+') | |
if empty(window) | |
return 0 | |
endif | |
call dispatch#dvtm#send('focusn '.window) | |
return !v:shell_error | |
endfunction | |
augroup dispatch_dvtm | |
autocmd! | |
autocmd VimResized * if !has('gui_running') | call dispatch#dvtm#poll() | endif | |
augroup END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See it in action: