Created
August 5, 2022 22:09
-
-
Save bcgraham/8065dee27b523be6df113e47fd997138 to your computer and use it in GitHub Desktop.
Open a source location in vim
This file contains 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
class Object | |
def vim | |
return unless File.chardev?('.vimpty') && respond_to?(:source_location) && source_location | |
message = %(\e]51;["call", "IrbApi_OpenBuf", #{source_location.inspect}]\a) | |
IO.write('.vimpty', message, mode: 'a') | |
end | |
end |
This file contains 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
function! MakeVimpty() | |
let ptybuf = term_start("NONE", {"term_name": "ptybuf", "hidden": 1, "term_kill": "quit"}) | |
call term_setapi(ptybuf, "IrbApi_") | |
call system("ln -fs ".job_info(term_getjob(ptybuf))['tty_out']." .vimpty") | |
exe "autocmd BufUnload <buffer=" . ptybuf . "> call delete('.vimpty')" | |
endfunction | |
function IrbApi_OpenBuf(bufnum, args) | |
let open_str = fnamemodify(a:args[0], ":.") | |
if exists('a:args[1]') | |
let open_str = "+". a:args[1] . " " . open_str | |
endif | |
silent exe "vert drop " . open_str | |
endfunc | |
call MakeVimpty() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment