Commit d99ea426 authored by HiPhish's avatar HiPhish

Use the `get()` function when possible

This function allows one to specify a default value, thus avoiding the
usual if-else ritual.
parent 4d7f068d
......@@ -73,11 +73,7 @@ endfunction
" settings are merged with the new one according to 'a:force'.
" ----------------------------------------------------------------------------
function! repl#define_repl(type, repl, force)
if !has_key(g:repl, a:type)
let g:repl[a:type] = a:repl
return
endif
let g:repl[a:type] = get(g:repl, a:type, a:repl)
call extend(g:repl[a:type], a:repl, a:force)
endf
......@@ -101,20 +97,16 @@ function! repl#spawn(mods, repl, type)
" Open a new buffer and launch the terminal
silent execute a:mods 'new'
let l:args = has_key(a:repl, 'args') ? a:repl.args : []
let l:args = get(a:repl, 'args', [])
silent execute 'terminal' a:repl.bin join(l:args, ' ')
if has_key(a:repl, 'syntax')
let l:Syntax = a:repl.syntax
if type(l:Syntax) == type(function('type'))
let l:Syntax = l:Syntax()
endif
silent execute 'set syntax='.l:Syntax
let l:Syntax = get(a:repl, 'syntax', '')
if type(l:Syntax) == type(function('type'))
let l:Syntax = l:Syntax()
endif
silent execute 'set syntax='.l:Syntax
if has_key(a:repl, 'title')
silent let b:term_title = a:repl.title
endif
silent let b:term_title = get(a:repl, 'title', b:term_title)
let b:repl = {
\ '-': {
......
......@@ -245,7 +245,7 @@ BOURNE SHELL *repl.nvim-sh*
'title': 'Bourne Shell',
}
<
The Bourne Shell defaults to your system `sh` binary. Beware that this might
The Bourne Shell defaults to your system `sh` binary. Beware that this might
actually be the Bourne Again Shell (`bash`) under the hood.
------------------------------------------------------------------------------
......
......@@ -58,9 +58,8 @@ function! s:send_to_repl(type, ...) range
Repl
endif
if has_key(g:repl[&ft], 'preproc')
let l:text = g:repl[&ft]['preproc'](l:text)
endif
" Apply the preprocessor function, or identity if there is none
let l:text = get(g:repl[&ft], 'preproc', {t -> t})(l:text)
call jobsend(g:repl[&ft].instances[0].job_id, l:text)
Repl
......
......@@ -102,11 +102,7 @@ function! s:repl(mods, bang, ...)
" first argument, that is the file type)
let l:repl.args = l:repl.args + a:000[1:]
if has_key(l:repl, 'spawn')
let l:instance = l:repl.spawn(a:mods, l:repl, l:type)
else
let l:instance = repl#spawn(a:mods, l:repl, l:type)
endif
let l:instance = get(l:repl, 'spawn', function('repl#spawn'))(a:mods, l:repl, l:type)
call s:register_instance(l:instance)
endfunction
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment