Skip to content
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

Vim array #364

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c77c2e0
made autcmds in lua, added autocmd for closing terminal
jam1015 Feb 7, 2023
f1b1ffc
conceputalized
jam1015 Feb 8, 2023
f76a87b
tried lua tables
jam1015 Feb 9, 2023
d326a3b
nothing
jam1015 Feb 9, 2023
9e746f9
made function that filters to only terminal buffers
jam1015 Feb 16, 2023
be1c2ed
made slime get last (most recent) item of list of terminals
jam1015 Feb 16, 2023
3ecd963
added todo
jam1015 Feb 16, 2023
82698f6
annotated todo
jam1015 Feb 16, 2023
2e87570
simplified functions that keep track of channels
jam1015 Feb 21, 2023
700376e
made neovim config stored as integer rather than string
jam1015 Feb 21, 2023
e499668
removed personal keymappings
jam1015 Feb 22, 2023
29c94d8
added some comments
jam1015 Feb 22, 2023
1704f1e
got rid of example commands I was playing with
jam1015 Feb 22, 2023
480a949
removed todo
jam1015 Feb 22, 2023
80c3df2
removed redundant if condition
jam1015 Feb 22, 2023
cb9c3e0
got rid of testing background change function
jam1015 Feb 22, 2023
1ef58b9
made better 'try again' message
jam1015 Feb 22, 2023
178f777
fixed whitespace formatting
jam1015 Feb 24, 2023
c390d27
fixed another whitespace issue
jam1015 Feb 24, 2023
12589d2
fixed indentation
jam1015 Feb 24, 2023
3ab0b71
fixed indentation more
jam1015 Feb 24, 2023
7126a58
further fixed intending
jam1015 Feb 24, 2023
3c23ae6
even further formatting changes
jam1015 Feb 24, 2023
a056105
hopefully final formatting changes for now
jam1015 Feb 25, 2023
e385def
fixed bug of get() trying to access nonexistent variables
jam1015 May 9, 2023
7f8d047
fixed bugs related to closing existing channels
jam1015 May 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 63 additions & 13 deletions autoload/slime.vim
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,24 @@ function! s:NeovimSend(config, text)
endfunction

function! s:NeovimConfig() abort
if !exists("b:slime_config")
let b:slime_config = {"jobid": get(g:, "slime_last_channel", "")}
end
if exists("g:slime_get_jobid")
let b:slime_config["jobid"] = g:slime_get_jobid()
let not_configured=1
if exists("g:slime_last_channel")
let b:slime_config = {"jobid": get(g:slime_last_channel, -1, "")}
if exists("g:slime_get_jobid")
let b:slime_config["jobid"] = g:slime_get_jobid()
let not_configured=0
else
if b:slime_config["jobid"] != "" && b:slime_config["jobid"] isnot v:null "it would be empty i f there was no slime_last_channel
let b:slime_config["jobid"] = str2nr(input("jobid: ", b:slime_config["jobid"]))
let not_configured=0
endif
endif
else
let b:slime_config["jobid"] = input("jobid: ", b:slime_config["jobid"])
end
echo "Terminal not detected; open neovim terminal and try again"
endif

return not_configured

endfunction

"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
Expand Down Expand Up @@ -378,23 +388,63 @@ function! s:_EscapeText(text)
end
endfunction

function! s:SlimeGetConfig()
" b:slime_config already configured...
function! s:SlimeExistsConfig() abort
" b:slime_config already not_configured...

let not_configured = 1
if exists("b:slime_config")
return
let not_configured = s:SlimeVerifyConfig()
return not_configured
end
" assume defaults, if they exist
if exists("g:slime_default_config")
let b:slime_config = g:slime_default_config
let not_configured = 0
end
" skip confirmation, if configured
" skip confirmation, if not_configured
if exists("g:slime_dont_ask_default") && g:slime_dont_ask_default
return
let not_configured = 0
return not_configured
end
" prompt user
call s:SlimeDispatch('Config')
let not_configured = s:SlimeDispatch('Config')
return not_configured
endfunction

function! s:SlimeVerifyConfig() abort
let not_configured = 1
if has('nvim') && get(g:, "slime_target", "") == "neovim"

if !exists("g:slime_last_channel")
echo "No last channel: open new neovim terminal"
return not_configured
endif

if index( g:slime_last_channel, b:slime_config['jobid'] ) >= 0
let not_configured = 0
return not_configured
endif
echo "Terminal channel number in config not found"
let not_configured = s:SlimeDispatch('Config')
return not_configured
else
let not_configured = 0 "not checking the value
return not_configured
endif
endfunction

function! s:SlimeGetConfig()
try
let not_configured = s:SlimeExistsConfig()
if not_configured
throw 'configuration_error'
endif
catch
echoerr 'Configuration error'
endtry
endfunction


function! slime#send_op(type, ...) abort
call s:SlimeGetConfig()

Expand Down
39 changes: 32 additions & 7 deletions plugin/slime.vim
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,35 @@ if !exists("g:slime_no_mappings") || !g:slime_no_mappings
endif

" for neovim (only), make slime_last_channel contain
" the channel id of the last opened terminal
if get(g:, "slime_target", "") == "neovim"
augroup nvim_slime
autocmd!
autocmd TermOpen * let g:slime_last_channel = &channel
augroup END
end
" the channel id of the last opened terminal, stored in an array with
" the most recent terminal job id the last element
if has('nvim') && get(g:, "slime_target", "") == "neovim"

function SlimeAddChannel() "adds terminal job id to the g:slime_last_channel variable
if !exists("g:slime_last_channel")
let g:slime_last_channel = [&channel]
echo g:slime_last_channel
else
call add(g:slime_last_channel, &channel)
echo g:slime_last_channel
endif
endfunction

function SlimeClearChannel() " checks if slime_last_channel exists and is nonempty; then fitlers slime_last_channel to only have existing channels
if !exists("g:slime_last_channel")
elseif len(g:slime_last_channel) == 1
unlet g:slime_last_channel
else
let bufinfo = getbufinfo()
call filter(bufinfo, {_, val -> has_key(val['variables'], "terminal_job_id") })
call map(bufinfo, {_, val -> val["variables"]["terminal_job_id"] })
call filter(g:slime_last_channel, {_, val -> index(bufinfo, val ) >= 0 })
endif
endfunction

augroup nvim_slime
autocmd!
autocmd TermOpen * call SlimeAddChannel()
autocmd TermClose * call SlimeClearChannel()
augroup END
endif